From e70d6ea64e711096af36b1234f8545b870ea5f45 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Sat, 05 Apr 2008 08:49:21 -0400
Subject: [PATCH] Apply changes from trunk to 0.1-stable

---
 program/include/rcube_mdb2.inc |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/program/include/rcube_mdb2.inc b/program/include/rcube_mdb2.inc
index 63d156a..72d9066 100644
--- a/program/include/rcube_mdb2.inc
+++ b/program/include/rcube_mdb2.inc
@@ -48,6 +48,7 @@
   var $db_handle = 0;         // Connection handle
   var $db_error = false;
   var $db_error_msg = '';
+  var $debug_mode = false;
 
   var $a_query_results = array('dummy');
   var $last_res_id = 0;
@@ -94,8 +95,11 @@
   function dsn_connect($dsn)
     {
     // Use persistent connections if available
-    $dbh = MDB2::connect($dsn,
-      array('persistent' => $this->db_pconn,
+    $dbh = MDB2::connect($dsn, array(
+        'persistent' => $this->db_pconn,
+        'emulate_prepared' => $this->debug_mode,
+        'debug' => $this->debug_mode,
+        'debug_handler' => 'mdb2_debug_handler',
         'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL));
 
     if (MDB2::isError($dbh))
@@ -155,6 +159,21 @@
     $this->db_connected = true;
     }
 
+
+  /**
+   * Activate/deactivate debug mode
+   *
+   * @param boolean True if SQL queries should be logged
+   */
+  function set_debug($dbg = true)
+  {
+    $this->debug_mode = $dbg;
+    if ($this->db_connected)
+    {
+      $this->db_handle->setOption('debug', $dbg);
+      $this->db_handle->setOption('emulate_prepared', $dbg);
+    }
+  }
 
     
   /**
@@ -413,6 +432,22 @@
     return $this->db_handle->quoteIdentifier($str);
     }
 
+  /**
+   * Escapes a string
+   *
+   * @param  string  The string to be escaped
+   * @return string  The escaped string
+   * @access public
+   * @since  0.1.1
+   */
+  function escapeSimple($str)
+    {
+    if (!$this->db_handle)
+      $this->db_connect('r');
+   
+    return $this->db_handle->escape($str);
+    }
+
 
   /**
    * Return SQL function for current time and date
@@ -569,4 +604,17 @@
 
   }  // end class rcube_db
 
+
+/* this is our own debug handler for the MDB2 connection */
+function mdb2_debug_handler(&$db, $scope, $message, $context = array())
+{
+  if ($scope != 'prepare')
+  {
+    $debug_output = $scope . '('.$db->db_index.'): ';
+    $debug_output .= $message . $db->getOption('log_line_break');
+    write_log('sqllog', $debug_output);
+  }
+}
+
+
 ?>

--
Gitblit v1.9.1