From 0677ca5a1e745643a9142081c4cbb7ea13e5a2e5 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Mon, 23 Jan 2006 18:12:23 -0500
Subject: [PATCH] Add created date to message cache

---
 program/include/rcube_mdb2.inc |   87 +++++++++++++++++++++++--------------------
 1 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/program/include/rcube_mdb2.inc b/program/include/rcube_mdb2.inc
index 53590aa..54a40e7 100755
--- a/program/include/rcube_mdb2.inc
+++ b/program/include/rcube_mdb2.inc
@@ -55,7 +55,7 @@
     function dsn_connect($dsn)
     {
         // Use persistent connections if available
-        $dbh = MDB2::factory($dsn, array('persistent' => TRUE));
+        $dbh = MDB2::factory($dsn, array('persistent' => $true));
         
         if (PEAR::isError($dbh))
             raise_error(array('code' => 500,
@@ -102,39 +102,24 @@
     }
 
     // Query database
-    
     function query()
-
     {
-
 		$params = func_get_args();
-
 		$query = array_shift($params);
-
-		
 
 		return $this->_query($query, 0, 0, $params);
-
     }
 
-   
 
 	function limitquery()
-
     {
 
 		$params = func_get_args();
-
 		$query = array_shift($params);
-
 		$offset = array_shift($params);
-
 		$numrows = array_shift($params);
 
-		
-
 		return $this->_query($query, $offset, $numrows, $params);
-
     }
     
     function _query($query, $offset, $numrows, $params)
@@ -149,12 +134,15 @@
 
         if ($this->db_provider == 'sqlite')
             $query = $this->_sqlite_prepare_query($query);
-            
+
         $this->db_handle->row_offset = $offset;
 		$this->db_handle->row_limit = $numrows;
-		
-        $result = $this->db_handle->query($query);
-        
+
+        //$result = $this->db_handle->query($query,$params);
+        $q = $this->db_handle->prepare($query);
+        $q->bindParamArray($params);
+        $result = $q->execute();
+
         if (PEAR::isError($result))
             raise_error(array('code' => 500,
                               'type' => 'db',
@@ -164,6 +152,7 @@
         
         return $this->_add_result($result, $query);
     }
+
 
     function num_rows($res_id=NULL)
     {
@@ -178,6 +167,7 @@
               return FALSE;
     }
 
+
     function affected_rows($res_id=NULL)
     {
         if (!$this->db_handle)
@@ -185,6 +175,7 @@
     
         return $this->db_handle->affectedRows();
     }
+
 
     function insert_id($sequence = '')
     {
@@ -209,42 +200,60 @@
         return $result->fetchRow(MDB2_FETCHMODE_ASSOC);
     }
 
-	function quoteIdentifier ( $str )
 
-	{
-
+    function quote($input, $type=null)
+    {
 		if (!$this->db_handle)
-
 			$this->db_connect('r');
 
-			
+		return $this->db_handle->quote($input, $type);
+    }
+
+
+	function quoteIdentifier($str)
+	{
+		if (!$this->db_handle)
+			$this->db_connect('r');
 
 		return $this->db_handle->quoteIdentifier($str);
-
 	}
-	
-	function unixtimestamp($field)
 
+	function quote_identifier($str)
 	{
+		return $this->quoteIdentifier($str);
+	}
 
+
+	function unixtimestamp($field)
+	{
 		switch($this->db_provider)
-
 			{
-
 			case 'pgsql':
-
 				return "EXTRACT (EPOCH FROM $field)";
-
 				break;
 
 			default:
-
 				return "UNIX_TIMESTAMP($field)";
-
 			}
-
 	}
-	
+
+
+	function format_date($timestamp)
+	  {
+		switch($this->db_provider)
+			{
+			case 'mysqli':
+			case 'mysql':
+				return "FROM_UNIXTIME($timestamp)";
+				break;
+			case 'sqlite':
+				return "datetime('$timestamp')";
+				break;
+			default:
+				return date("Y-m-d H:i:s", $timestamp);
+			}
+	  }
+
     function _add_result($res, $query)
     {
         // sql error occured
@@ -298,10 +307,8 @@
         if (!is_string($query))
             return ($query);
 
-        $search = array('/NOW\(\)/',
-                        '/`/');
-        $replace = array("datetime('now')",
-                         '"');
+        $search = array('/NOW\(\)/i', '/`/');
+        $replace = array("datetime('now')", '"');
         $query = preg_replace($search, $replace, $query);
 
         return ($query);

--
Gitblit v1.9.1