From 52877803f86c4f1b4e8a40b9a53b40586f653f2f Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 02 Jun 2012 10:59:01 -0400
Subject: [PATCH] Merge pull request #12 from mrhein/master

---
 program/include/rcube_mdb2.php |   39 +++++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/program/include/rcube_mdb2.php b/program/include/rcube_mdb2.php
index 0139bdc..a255d9e 100644
--- a/program/include/rcube_mdb2.php
+++ b/program/include/rcube_mdb2.php
@@ -18,9 +18,6 @@
  +-----------------------------------------------------------------------+
  | Author: Lukas Kahwe Smith <smith@pooteeweet.org>                      |
  +-----------------------------------------------------------------------+
-
- $Id$
-
 */
 
 
@@ -51,6 +48,7 @@
     private $a_query_results = array('dummy');
     private $last_res_id = 0;
     private $tables;
+    private $variables;
 
 
     /**
@@ -213,6 +211,31 @@
     public function is_replicated()
     {
       return !empty($this->db_dsnr) && $this->db_dsnw != $this->db_dsnr;
+    }
+
+
+    /**
+     * Get database runtime variables
+     *
+     * @param string Variable name
+     * @param mixed  Default value if var is not set
+     * @return mixed Variable value or default
+     */
+    public function get_variable($varname, $default = null)
+    {
+        if (!isset($this->variables)) {
+            $this->variables = array();
+
+            // only mysql and postgres are know to support this
+            if ($this->db_provider == 'pgsql' || $this->db_provider == 'mysql' || $this->db_provider == 'mysqli') {
+                $this->db_connect('r');
+                $query = $this->db_provider == 'pgsql' ? 'SHOW ALL' : 'SHOW VARIABLES';
+                foreach ((array)$this->db_handle->queryAll($query) as $row)
+                    $this->variables[$row[0]] = $row[1];
+            }
+        }
+
+        return isset($this->variables[$varname]) ? $this->variables[$varname] : $default;
     }
 
 
@@ -826,7 +849,7 @@
         if ($scope != 'prepare') {
             $debug_output = sprintf('%s(%d): %s;',
                 $scope, $db->db_index, rtrim($message, ';'));
-            rcmail::write_log('sql', $debug_output);
+            rcube::write_log('sql', $debug_output);
         }
     }
 
@@ -840,12 +863,12 @@
      */
     public function table_name($table)
     {
-        $rcmail = rcube::get_instance();
+        $rcube = rcube::get_instance();
 
         // return table name if configured
         $config_key = 'db_table_'.$table;
 
-        if ($name = $rcmail->config->get($config_key)) {
+        if ($name = $rcube->config->get($config_key)) {
             return $name;
         }
 
@@ -863,12 +886,12 @@
      */
     public function sequence_name($sequence)
     {
-        $rcmail = rcube::get_instance();
+        $rcube = rcube::get_instance();
 
         // return sequence name if configured
         $config_key = 'db_sequence_'.$sequence;
 
-        if ($name = $rcmail->config->get($config_key)) {
+        if ($name = $rcube->config->get($config_key)) {
             return $name;
         }
 

--
Gitblit v1.9.1