From 2c633703e97eb6e7aa7ba840ef86b1fc1bd98ada Mon Sep 17 00:00:00 2001
From: svncommit <devs@roundcube.net>
Date: Wed, 23 May 2007 23:49:19 -0400
Subject: [PATCH] upgrade to TinyMCE v2.1.1.1

---
 program/include/rcube_db.inc |  124 ++++++++++++++++++++++++++++++++---------
 1 files changed, 96 insertions(+), 28 deletions(-)

diff --git a/program/include/rcube_db.inc b/program/include/rcube_db.inc
old mode 100755
new mode 100644
index e54dcc9..626cb64
--- a/program/include/rcube_db.inc
+++ b/program/include/rcube_db.inc
@@ -5,7 +5,7 @@
  | program/include/rcube_db.inc                                          |
  |                                                                       |
  | This file is part of the RoundCube Webmail client                     |
- | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
+ | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland                 |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -14,6 +14,7 @@
  |                                                                       |
  +-----------------------------------------------------------------------+
  | Author: David Saez Padros <david@ols.es>                              |
+ |         Thomas Bruederli <roundcube@gmail.com>                        |
  +-----------------------------------------------------------------------+
 
  $Id$
@@ -35,7 +36,7 @@
  * @package    RoundCube Webmail
  * @author     David Saez Padros <david@ols.es>
  * @author     Thomas Bruederli <roundcube@gmail.com>
- * @version    1.14
+ * @version    1.17
  * @link       http://pear.php.net/package/DB
  */
 class rcube_db
@@ -45,6 +46,9 @@
   var $db_connected = false;  // Already connected ?
   var $db_mode = '';          // Connection mode
   var $db_handle = 0;         // Connection handle
+  var $db_pconn = false;      // Use persistent connections
+  var $db_error = false;
+  var $db_error_msg = '';
 
   var $a_query_results = array('dummy');
   var $last_res_id = 0;
@@ -56,13 +60,14 @@
    * @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 = DB::parseDSN($db_dsnw);
     $this->db_provider = $dsn_array['phptype'];        
@@ -74,20 +79,10 @@
    *
    * @see  rcube_db::__construct
    */
-  function rcube_db($db_dsnw,$db_dsnr='')
+  function rcube_db($db_dsnw, $db_dsnr='', $pconn=false)
     {
-    $this->__construct($db_dsnw,$db_dsnr);
+    $this->__construct($db_dsnw, $db_dsnr, $pconn);
     }
-
-
-  /**
-   * Object destructor
-   */
-  function __destruct()
-    {
-    // before closing the database connection, write session data
-    session_write_close();
-    } 
 
 
   /**
@@ -100,12 +95,17 @@
   function dsn_connect($dsn)
     {
     // Use persistent connections if available
-    $dbh = DB::connect($dsn, array('persistent' => TRUE));
+    $dbh = DB::connect($dsn, array('persistent' => $this->db_pconn));
         
     if (DB::isError($dbh))
       {
-      raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
-                        'message' => $dbh->getMessage()), TRUE, FALSE);
+      $this->db_error = TRUE;
+      $this->db_error_msg = $dbh->getMessage();
+
+      raise_error(array('code' => 603, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
+                        'message' => $this->db_error_msg), TRUE, FALSE);
+                        
+      return FALSE;
       }
 
     else if ($this->db_provider=='sqlite')
@@ -152,7 +152,18 @@
       $dsn = $this->db_dsnw;
 
     $this->db_handle = $this->dsn_connect($dsn);
-    $this->db_connected = true;
+    $this->db_connected = $this->db_handle ? TRUE : FALSE;
+    }
+    
+    
+  /**
+   * Getter for error state
+   *
+   * @param  boolean  True on error
+   */
+  function is_error()
+    {
+    return $this->db_error ? $this->db_error_msg : FALSE;
     }
 
 
@@ -213,6 +224,9 @@
       $mode='w';
         
     $this->db_connect($mode);
+    
+    if (!$this->db_connected)
+      return FALSE;
 
     if ($this->db_provider == 'sqlite')
       $this->_sqlite_prepare();
@@ -278,14 +292,17 @@
     switch($this->db_provider)
       {
       case 'pgsql':
-        // PostgreSQL uses sequences
         $result = &$this->db_handle->getOne("SELECT CURRVAL('$sequence')");
         if (DB::isError($result))
-          {
           raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 
                             'message' => $result->getMessage()), TRUE, FALSE);
-          }
+        return $result;
 
+      case 'mssql':
+        $result = &$this->db_handle->getOne("SELECT @@IDENTITY");
+        if (DB::isError($result))
+          raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__, 
+                            'message' => $result->getMessage()), TRUE, FALSE);
         return $result;
                 
       case 'mysql': // This is unfortuneate
@@ -293,7 +310,7 @@
 
       case 'mysqli':
         return mysqli_insert_id($this->db_handle->connection);
-	
+
       case 'sqlite':
         return sqlite_last_insert_rowid($this->db_handle->connection);
 
@@ -314,17 +331,47 @@
   function fetch_assoc($res_id=NULL)
     {
     $result = $this->_get_result($res_id);
+    return $this->_fetch_row($result, DB_FETCHMODE_ASSOC);
+    }
 
-    if (DB::isError($result))
+
+  /**
+   * Get an index array for one row
+   * If no query handle is specified, the last query will be taken as reference
+   *
+   * @param  number  Optional query handle identifier
+   * @return mixed   Array with col values or FALSE on failure
+   * @access public
+   */
+  function fetch_array($res_id=NULL)
+    {
+    $result = $this->_get_result($res_id);
+    return $this->_fetch_row($result, DB_FETCHMODE_ORDERED);
+    }
+
+
+  /**
+   * Get co values for a result row
+   *
+   * @param  object  Query result handle
+   * @param  number  Fetch mode identifier
+   * @return mixed   Array with col values or FALSE on failure
+   * @access private
+   */
+  function _fetch_row($result, $mode)
+    {
+    if (!$result || DB::isError($result))
       {
       raise_error(array('code' => 500, 'type' => 'db', 'line' => __LINE__, 'file' => __FILE__,
                         'message' => $this->db_link->getMessage()), TRUE, FALSE);
       return FALSE;
       }
+      elseif (!is_object($result))
+      return FALSE;
                          
-    return $result->fetchRow(DB_FETCHMODE_ASSOC);
+    return $result->fetchRow($mode);
     }
-
+    
 
   /**
    * Formats input so it can be safely used in a query
@@ -379,6 +426,25 @@
     }
 
 
+  /*
+   * 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
    *
@@ -392,7 +458,9 @@
       {
       case 'pgsql':
         return "EXTRACT (EPOCH FROM $field)";
-        break;
+
+      case 'mssql':
+        return "datediff(s, '1970-01-01 00:00:00', $field)";
 
       default:
         return "UNIX_TIMESTAMP($field)";
@@ -414,7 +482,7 @@
       case 'mysqli':
       case 'mysql':
       case 'sqlite':
-        return "FROM_UNIXTIME($timestamp)";
+        return sprintf("FROM_UNIXTIME(%d)", $timestamp);
 
       default:
         return date("'Y-m-d H:i:s'", $timestamp);

--
Gitblit v1.9.1