summaryrefslogtreecommitdiff
path: root/program/lib/Roundcube/rcube_db_sqlite.php
diff options
context:
space:
mode:
Diffstat (limited to 'program/lib/Roundcube/rcube_db_sqlite.php')
-rw-r--r--program/lib/Roundcube/rcube_db_sqlite.php47
1 files changed, 28 insertions, 19 deletions
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
@@ -29,6 +29,13 @@ class rcube_db_sqlite extends rcube_db
public $db_provider = 'sqlite';
/**
+ * Database character set
+ */
+ protected function set_charset($charset)
+ {
+ }
+
+ /**
* Prepare connection
*/
protected function conn_prepare($dsn)
@@ -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");
}
/**