Aleksander Machniak
2012-07-08 c389a85978bc5cf8f0f9d06c58664a35c4746447
Add get_variable() implementation
3 files modified
77 ■■■■■ changed files
program/include/rcube_db.php 17 ●●●●● patch | view | raw | blame | history
program/include/rcube_db_mysql.php 23 ●●●●● patch | view | raw | blame | history
program/include/rcube_db_pgsql.php 37 ●●●● patch | view | raw | blame | history
program/include/rcube_db.php
@@ -42,6 +42,7 @@
    protected $a_query_results = array('dummy');
    protected $last_res_id = 0;
    protected $tables;
    protected $variables;
    protected $db_index = 0;
    protected $options = array(
@@ -280,6 +281,20 @@
    }
    /**
     * Get database runtime variables
     *
     * @param string $varname  Variable name
     * @param mixed  $default  Default value if variable is not set
     *
     * @return mixed Variable value or default
     */
    public function get_variable($varname, $default = null)
    {
        // to be implemented by driver class
        return $default;
    }
    /**
     * Execute a SQL query
     *
     * @param  string  SQL query to execute
@@ -332,7 +347,7 @@
    protected function _query($query, $offset, $numrows, $params)
    {
        // Read or write ?
        $mode = preg_match('/^select/i', ltrim($query)) ? 'r' : 'w';
        $mode = preg_match('/^(select|show)/i', ltrim($query)) ? 'r' : 'w';
        $this->db_connect($mode);
program/include/rcube_db_mysql.php
@@ -90,4 +90,27 @@
        return $result;
    }
    /**
     * Get database runtime variables
     *
     * @param string $varname  Variable name
     * @param mixed  $default  Default value if variable is not set
     *
     * @return mixed Variable value or default
     */
    public function get_variable($varname, $default = null)
    {
        if (!isset($this->variables)) {
            $this->variables = array();
            $result = $this->query('SHOW VARIABLES');
            while ($sql_arr = $this->fetch_array($result)) {
                $this->variables[$row[0]] = $row[1];
            }
        }
        return isset($this->variables[$varname]) ? $this->variables[$varname] : $default;
    }
}
program/include/rcube_db_pgsql.php
@@ -1,6 +1,6 @@
<?php
/*
/**
 +-----------------------------------------------------------------------+
 | program/include/rcube_db_pgsql.php                                    |
 |                                                                       |
@@ -26,8 +26,8 @@
 *
 * This is a wrapper for the PHP PDO
 *
 * @package    Database
 * @version    1.0
 * @package Database
 * @version 1.0
 */
class rcube_db_pgsql extends rcube_db
{
@@ -80,7 +80,36 @@
     */
    public function ilike($column, $value)
    {
        return $this->quote_identifier($column).' ILIKE '.$this->quote($value);
        return $this->quote_identifier($column) . ' ILIKE ' . $this->quote($value);
    }
    /**
     * Get database runtime variables
     *
     * @param string $varname  Variable name
     * @param mixed  $default  Default value if variable is not set
     *
     * @return mixed Variable value or default
     */
    public function get_variable($varname, $default = null)
    {
        // There's a known case when max_allowed_packet is queried
        // PostgreSQL doesn't have such limit, return immediately
        if ($varname == 'max_allowed_packet') {
            return $default;
        }
        if (!isset($this->variables)) {
            $this->variables = array();
            $result = $this->query('SHOW ALL');
            while ($row = $this->fetch_array($result)) {
                $this->variables[$row[0]] = $row[1];
            }
        }
        return isset($this->variables[$varname]) ? $this->variables[$varname] : $default;
    }
}