From 59478e06c25303a790a0840ab2ac30662c4ef781 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Tue, 5 Aug 2014 16:46:22 +0200 Subject: c'est la merde.. --- program/lib/Roundcube/rcube_db_sqlite.php | 47 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'program/lib/Roundcube/rcube_db_sqlite.php') diff --git a/program/lib/Roundcube/rcube_db_sqlite.php b/program/lib/Roundcube/rcube_db_sqlite.php index b66c56097..145b8a371 100644 --- a/program/lib/Roundcube/rcube_db_sqlite.php +++ b/program/lib/Roundcube/rcube_db_sqlite.php @@ -28,6 +28,13 @@ class rcube_db_sqlite extends rcube_db { public $db_provider = 'sqlite'; + /** + * Database character set + */ + protected function set_charset($charset) + { + } + /** * Prepare connection */ @@ -49,6 +56,10 @@ class rcube_db_sqlite extends rcube_db */ protected function conn_configure($dsn, $dbh) { + // we emulate via callback some missing functions + $dbh->sqliteCreateFunction('unix_timestamp', array('rcube_db_sqlite', 'sqlite_unix_timestamp'), 1); + $dbh->sqliteCreateFunction('now', array('rcube_db_sqlite', 'sqlite_now'), 0); + // Initialize database structure in file is empty if (!empty($dsn['database']) && !filesize($dsn['database'])) { $data = file_get_contents(RCUBE_INSTALL_PATH . 'SQL/sqlite.initial.sql'); @@ -72,32 +83,30 @@ class rcube_db_sqlite extends rcube_db } /** - * Return SQL statement to convert a field value into a unix timestamp - * - * @param string $field Field name - * - * @return string SQL statement to use in query - * @deprecated + * Callback for sqlite: unix_timestamp() */ - public function unixtimestamp($field) + public static function sqlite_unix_timestamp($timestamp = '') { - return "strftime('%s', $field)"; + $timestamp = trim($timestamp); + if (!$timestamp) { + $ret = time(); + } + else if (!preg_match('/^[0-9]+$/s', $timestamp)) { + $ret = strtotime($timestamp); + } + else { + $ret = $timestamp; + } + + return $ret; } /** - * 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 + * Callback for sqlite: now() */ - public function now($interval = 0) + public static function sqlite_now() { - if ($interval) { - $add = ($interval > 0 ? '+' : '') . intval($interval) . ' seconds'; - } - - return "datetime('now'" . ($add ? ",'$add'" : "") . ")"; + return date("Y-m-d H:i:s"); } /** -- cgit v1.2.3