From 0d94fd45f422fe0d0460f5db7a7761f56bc18236 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Tue, 19 Jun 2012 10:46:41 +0200 Subject: New database layer based on PHP PDO --- program/include/rcube_db_mssql.php | 135 +++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 program/include/rcube_db_mssql.php (limited to 'program/include/rcube_db_mssql.php') diff --git a/program/include/rcube_db_mssql.php b/program/include/rcube_db_mssql.php new file mode 100644 index 000000000..1f7328c3e --- /dev/null +++ b/program/include/rcube_db_mssql.php @@ -0,0 +1,135 @@ + | + +-----------------------------------------------------------------------+ +*/ + + +/** + * Database independent query interface + * + * This is a wrapper for the PHP PDO + * + * @package Database + * @version 1.0 + */ +class rcube_db_mssql extends rcube_db +{ + protected function init() + { + $this->options['identifier_start'] = '['; + $this->options['identifier_end'] = ']'; + } + + protected function set_charset($charset) + { + } + + + /** + * Return SQL function for current time and date + * + * @return string SQL function to use in query + */ + public function now() + { + return "getdate()"; + } + + + /** + * 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 + * @deprecated + */ + public function unixtimestamp($field) + { + return "DATEDIFF(second, '19700101', $field) + DATEDIFF(second, GETDATE(), GETUTCDATE())"; + } + + + /** + * Abstract SQL statement for value concatenation + * + * @return string SQL statement to be used in query + */ + public function concat(/* col1, col2, ... */) + { + $args = func_get_args(); + + if (is_array($args[0])) { + $args = $args[0]; + } + + return '(' . join('+', $args) . ')'; + } + + + /** + * Adds TOP (LIMIT,OFFSET) clause to the query + * + */ + protected function set_limit($query, $limit = 0, $offset = 0) + { + // code from MDB2 package + if ($limit > 0) { + $fetch = $offset + $limit; + return preg_replace('/^([\s(])*SELECT( DISTINCT)?(?!\s*TOP\s*\()/i', + "\\1SELECT\\2 TOP $fetch", $query); + } + +// @TODO: proper OFFSET handling i _fetch_row() + + return $query; + } + + + /** + * Returns PDO DSN string from DSN array (parse_dsn() result) + */ + protected function dsn_string($dsn) + { + $params = array(); + $result = $dsn['phptype'] . ':'; + + if ($dsn['hostspec']) { + $host = $dsn['hostspec']; + if ($dsn['port']) { + $host .= ',' . $dsn['port']; + } + $params[] = 'host=' . $host; + } + + if ($dsn['database']) { + $params[] = 'dbname=' . $dsn['database']; + } + + if (!empty($params)) { + $result .= implode(';', $params); + } + + return $result; + } +} -- cgit v1.2.3