| | |
| | | public $db_provider = 'postgres'; |
| | | |
| | | /** |
| | | * Driver-specific configuration of database connection |
| | | * |
| | | * @param array $dsn DSN for DB connections |
| | | * @param PDO $dbh Connection handler |
| | | */ |
| | | protected function conn_configure($dsn, $dbh) |
| | | { |
| | | $dbh->query("SET NAMES 'utf8'"); |
| | | } |
| | | |
| | | /** |
| | | * Get last inserted record ID |
| | | * |
| | | * @param string $table Table name (to find the incremented sequence) |
| | |
| | | // Note: we support only one sequence per table |
| | | // Note: The sequence name must be <table_name>_seq |
| | | $sequence = $table . '_seq'; |
| | | $rcube = rcube::get_instance(); |
| | | |
| | | // return sequence name if configured |
| | | if ($prefix = $rcube->config->get('db_prefix')) { |
| | | // modify sequence name if prefix is configured |
| | | if ($prefix = $this->options['table_prefix']) { |
| | | return $prefix . $sequence; |
| | | } |
| | | |
| | |
| | | /** |
| | | * Return SQL statement to convert a field value into a unix timestamp |
| | | * |
| | | * This method is deprecated and should not be used anymore due to limitations |
| | | * of timestamp functions in Mysql (year 2038 problem) |
| | | * |
| | | * @param string $field Field name |
| | | * |
| | | * @return string SQL statement to use in query |
| | |
| | | public function unixtimestamp($field) |
| | | { |
| | | return "EXTRACT (EPOCH FROM $field)"; |
| | | } |
| | | |
| | | /** |
| | | * Return SQL function for current time and date |
| | | * |
| | | * @param int $interval Optional interval (in seconds) to add/subtract |
| | | * |
| | | * @return string SQL function to use in query |
| | | */ |
| | | public function now($interval = 0) |
| | | { |
| | | if ($interval) { |
| | | $add = ' ' . ($interval > 0 ? '+' : '-') . " interval '"; |
| | | $add .= $interval > 0 ? intval($interval) : intval($interval) * -1; |
| | | $add .= " seconds'"; |
| | | } |
| | | |
| | | return "now()" . $add; |
| | | } |
| | | |
| | | /** |
| | |
| | | return $result; |
| | | } |
| | | |
| | | /** |
| | | * Parse SQL file and fix table names according to table prefix |
| | | */ |
| | | protected function fix_table_names($sql) |
| | | { |
| | | if (!$this->options['table_prefix']) { |
| | | return $sql; |
| | | } |
| | | |
| | | $sql = parent::fix_table_names($sql); |
| | | |
| | | // replace sequence names, and other postgres-specific commands |
| | | $sql = preg_replace_callback( |
| | | '/((SEQUENCE |RENAME TO |nextval\()["\']*)([^"\' \r\n]+)/', |
| | | array($this, 'fix_table_names_callback'), |
| | | $sql |
| | | ); |
| | | |
| | | return $sql; |
| | | } |
| | | } |