From b79cc545ec020f7dd4bd83dcd06af3cf2b1fcaff Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 28 Aug 2012 05:20:20 -0400
Subject: [PATCH] Improvements/fixes for Larry skin

---
 program/include/rcube_db.php |   57 +++++++++++++++++++++++++++------------------------------
 1 files changed, 27 insertions(+), 30 deletions(-)

diff --git a/program/include/rcube_db.php b/program/include/rcube_db.php
index f24e959..f97d70a 100644
--- a/program/include/rcube_db.php
+++ b/program/include/rcube_db.php
@@ -196,7 +196,7 @@
     }
 
     /**
-     * Connect to appropiate database depending on the operation
+     * Connect to appropriate database depending on the operation
      *
      * @param string $mode Connection mode (r|w)
      */
@@ -252,13 +252,31 @@
     }
 
     /**
+     * Writes debug information/query to 'sql' log file
+     *
+     * @param string $query SQL query
+     */
+    protected function debug($query)
+    {
+        if ($this->options['debug_mode']) {
+            rcube::write_log('sql', '[' . (++$this->db_index) . '] ' . $query . ';');
+        }
+    }
+
+    /**
      * Getter for error state
      *
-     * @return boolean True on error
+     * @param int $res_id Optional query result identifier
+     *
+     * @return string Error message
      */
-    public function is_error()
+    public function is_error($res_id = null)
     {
-        return $this->db_error ? $this->db_error_msg : false;
+        if ($res_id !== null) {
+            return $this->_get_result($res_id) === false ? $this->db_error_msg : null;
+        }
+
+        return $this->db_error ? $this->db_error_msg : null;
     }
 
     /**
@@ -378,9 +396,7 @@
 
         $query = rtrim($query, ';');
 
-        if ($this->options['debug_mode']) {
-            rcube::write_log('sql', '[' . (++$this->db_index) . '] ' . $query . ';');
-        }
+        $this->debug($query);
 
         $query = $this->dbh->query($query);
 
@@ -416,7 +432,6 @@
 
     /**
      * Get last inserted record ID
-     * For Postgres databases, a sequence name is required
      *
      * @param string $table Table name (to find the incremented sequence)
      *
@@ -559,6 +574,10 @@
         // handle int directly for better performance
         if ($type == 'integer' || $type == 'int') {
             return intval($input);
+        }
+
+        if (is_null($input)) {
+            return 'NULL';
         }
 
         // create DB handle if not available
@@ -805,28 +824,6 @@
         }
 
         return $table;
-    }
-
-    /**
-     * Return correct name for a specific database sequence
-     * (used for Postgres only)
-     *
-     * @param string $sequence Secuence name
-     *
-     * @return string Translated sequence name
-     */
-    public function sequence_name($sequence)
-    {
-        $rcube = rcube::get_instance();
-
-        // return sequence name if configured
-        $config_key = 'db_sequence_'.$sequence;
-
-        if ($name = $rcube->config->get($config_key)) {
-            return $name;
-        }
-
-        return $sequence;
     }
 
     /**

--
Gitblit v1.9.1