From 7c8fd8031038e7958ef4dbb059e86decd6fefa28 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 30 Jun 2012 12:41:18 -0400
Subject: [PATCH] Show explicit error message when provided hostname is invalid (#1488550)

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

diff --git a/program/include/rcube_mdb2.php b/program/include/rcube_mdb2.php
index 6acb3a0..721963b 100644
--- a/program/include/rcube_mdb2.php
+++ b/program/include/rcube_mdb2.php
@@ -48,6 +48,7 @@
     private $a_query_results = array('dummy');
     private $last_res_id = 0;
     private $tables;
+    private $variables;
 
 
     /**
@@ -210,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;
     }
 
 
@@ -665,6 +691,11 @@
             case 'mssql':
             case 'sqlsrv':
                 $delim = ' + ';
+                // Modify arguments, because + operator requires them to be of type varchar (#1488505)
+                // with SQL Server 2012 we can use just CONCAT(), but we need to support older versions
+                foreach ($args as $idx => $arg) {
+                    $args[$idx] = "CAST($arg AS varchar)";
+                }
                 break;
             default:
                 $delim = ' || ';

--
Gitblit v1.9.1