summaryrefslogtreecommitdiff
path: root/program/include/rcube_mdb2.inc
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2008-03-19 14:36:47 +0000
committerthomascube <thomas@roundcube.net>2008-03-19 14:36:47 +0000
commit9814721e8ddee4e26cc58cd47301e5d741048a22 (patch)
tree7ae2e67066ba35fe6aa61d1501eefaafc37ee040 /program/include/rcube_mdb2.inc
parent0714b7e09d9a4f26d76bf5ccbe05c356a961f4a2 (diff)
Enable SQL logging (set 'sql_debug' config param to true); Switch to emulated prepare mode for better performance
Diffstat (limited to 'program/include/rcube_mdb2.inc')
-rw-r--r--program/include/rcube_mdb2.inc33
1 files changed, 31 insertions, 2 deletions
diff --git a/program/include/rcube_mdb2.inc b/program/include/rcube_mdb2.inc
index 63d156a08..98eaf7e43 100644
--- a/program/include/rcube_mdb2.inc
+++ b/program/include/rcube_mdb2.inc
@@ -48,6 +48,7 @@ class rcube_mdb2
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 @@ class rcube_mdb2
function dsn_connect($dsn)
{
// Use persistent connections if available
- $dbh = MDB2::connect($dsn,
- array('persistent' => $this->db_pconn,
+ $dbh = MDB2::connect($dsn, array(
+ 'emulate_prepared' => true,
+ 'persistent' => $this->db_pconn,
+ 'debug' => $this->debug_mode,
+ 'debug_handler' => 'mdb2_debug_handler',
'portability' => MDB2_PORTABILITY_ALL ^ MDB2_PORTABILITY_EMPTY_TO_NULL));
if (MDB2::isError($dbh))
@@ -156,6 +160,18 @@ class rcube_mdb2
}
+ /**
+ * 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);
+ }
+
/**
* Getter for error state
@@ -569,4 +585,17 @@ class rcube_mdb2
} // 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);
+ }
+}
+
+
?>