From 0b36d151572e050b51d82e7429fee847ebb33e22 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 20 Nov 2014 06:03:22 -0500
Subject: [PATCH] Add method to display operation (uploading) progress in UI message

---
 program/lib/Roundcube/rcube_db_sqlite.php |   60 +++++++++++++++++++++---------------------------------------
 1 files changed, 21 insertions(+), 39 deletions(-)

diff --git a/program/lib/Roundcube/rcube_db_sqlite.php b/program/lib/Roundcube/rcube_db_sqlite.php
index 9aa67d0..b66c560 100644
--- a/program/lib/Roundcube/rcube_db_sqlite.php
+++ b/program/lib/Roundcube/rcube_db_sqlite.php
@@ -2,8 +2,6 @@
 
 /**
  +-----------------------------------------------------------------------+
- | program/include/rcube_db_sqlite.php                                   |
- |                                                                       |
  | This file is part of the Roundcube Webmail client                     |
  | Copyright (C) 2005-2012, The Roundcube Dev Team                       |
  |                                                                       |
@@ -14,12 +12,10 @@
  | PURPOSE:                                                              |
  |   Database wrapper class that implements PHP PDO functions            |
  |   for SQLite database                                                 |
- |                                                                       |
  +-----------------------------------------------------------------------+
  | Author: Aleksander Machniak <alec@alec.pl>                            |
  +-----------------------------------------------------------------------+
 */
-
 
 /**
  * Database independent query interface
@@ -31,13 +27,6 @@
 class rcube_db_sqlite extends rcube_db
 {
     public $db_provider = 'sqlite';
-
-    /**
-     * Database character set
-     */
-    protected function set_charset($charset)
-    {
-    }
 
     /**
      * Prepare connection
@@ -60,13 +49,9 @@
      */
     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(INSTALL_PATH . 'SQL/sqlite.initial.sql');
+            $data = file_get_contents(RCUBE_INSTALL_PATH . 'SQL/sqlite.initial.sql');
 
             if (strlen($data)) {
                 $this->debug('INITIALIZE DATABASE');
@@ -87,30 +72,32 @@
     }
 
     /**
-     * Callback for sqlite: unix_timestamp()
+     * 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
      */
-    public static function sqlite_unix_timestamp($timestamp = '')
+    public function unixtimestamp($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 "strftime('%s', $field)";
     }
 
     /**
-     * Callback for sqlite: now()
+     * 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 static function sqlite_now()
+    public function now($interval = 0)
     {
-        return date("Y-m-d H:i:s");
+        if ($interval) {
+            $add = ($interval > 0 ? '+' : '') . intval($interval) . ' seconds';
+        }
+
+        return "datetime('now'" . ($add ? ",'$add'" : "") . ")";
     }
 
     /**
@@ -124,12 +111,7 @@
             $q = $this->query('SELECT name FROM sqlite_master'
                 .' WHERE type = \'table\' ORDER BY name');
 
-            if ($res = $this->_get_result($q)) {
-                $this->tables = $res->fetchAll(PDO::FETCH_COLUMN, 0);
-            }
-            else {
-                $this->tables = array();
-            }
+            $this->tables = $q ? $q->fetchAll(PDO::FETCH_COLUMN, 0) : array();
         }
 
         return $this->tables;

--
Gitblit v1.9.1