]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/include/rcube_mdb2.inc
Imported Upstream version 0.1~rc1~dfsg
[roundcube.git] / program / include / rcube_mdb2.inc
index f37c26962ac9a3ec928d79e6c34e8d32a41c91d4..5f81aeadafc87b5077ede80e4b5e8e8a99068cc6 100755 (executable)
@@ -16,7 +16,7 @@
  | Author: Lukas Kahwe Smith <smith@pooteeweet.org>                      |
  +-----------------------------------------------------------------------+
 
- $Id: rcube_mdb2.inc 239 2006-05-18 21:25:11Z roundcube $
+ $Id: rcube_mdb2.inc 420 2006-12-20 14:07:46Z thomasb $
 
 */
 
@@ -59,14 +59,15 @@ class rcube_db
    * @param  string  DSN for read/write operations
    * @param  string  Optional DSN for read only operations
    */
-  function __construct($db_dsnw, $db_dsnr='')
+  function __construct($db_dsnw, $db_dsnr='', $pconn=false)
     {
     if ($db_dsnr=='')
       $db_dsnr=$db_dsnw;
 
     $this->db_dsnw = $db_dsnw;
     $this->db_dsnr = $db_dsnr;
-
+    $this->db_pconn = $pconn;
+    
     $dsn_array = MDB2::parseDSN($db_dsnw);
     $this->db_provider = $dsn_array['phptype'];
     }
@@ -93,7 +94,7 @@ class rcube_db
   function dsn_connect($dsn)
     {
     // Use persistent connections if available
-    $dbh = MDB2::connect($dsn, array('persistent' => TRUE, 'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL));
+    $dbh = MDB2::connect($dsn, array('persistent' => $this->db_pconn, 'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL));
 
     if (PEAR::isError($dbh))
       {
@@ -103,13 +104,14 @@ class rcube_db
       raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
                         'message' => $dbh->getMessage()), TRUE, FALSE);
       }
-
     else if ($this->db_provider=='sqlite')
       {
       $dsn_array = MDB2::parseDSN($dsn);
       if (!filesize($dsn_array['database']) && !empty($this->sqlite_initials))
         $this->_sqlite_create_database($dbh, $this->sqlite_initials);
       }
+    else
+      $dbh->setCharset('utf8');
 
     return $dbh;
     }
@@ -285,7 +287,7 @@ class rcube_db
     if (!$this->db_handle)
       return FALSE;
 
-    return $result;
+    return $this->_get_result($result);
     }
 
 
@@ -410,6 +412,25 @@ class rcube_db
     }
 
 
+  /**
+   * Return SQL function for current time and date
+   *
+   * @return string SQL function to use in query
+   * @access public
+   */
+  function now()
+    {
+    switch($this->db_provider)
+      {
+      case 'mssql':
+        return "getdate()";
+
+      default:
+        return "now()";
+      }
+    }
+
+
   /**
    * Return SQL statement to convert a field value into a unix timestamp
    *
@@ -425,6 +446,9 @@ class rcube_db
         return "EXTRACT (EPOCH FROM $field)";
         break;
 
+      case 'mssql':
+        return "datediff(s, '1970-01-01 00:00:00', $field)";
+
       default:
         return "UNIX_TIMESTAMP($field)";
       }