Thomas Bruederli
2014-06-04 3412e50b54e3daac8745234e21ab6e72be0ed165
program/lib/Roundcube/rcube_db.php
@@ -392,7 +392,7 @@
     */
    protected function _query($query, $offset, $numrows, $params)
    {
        $query = trim($query);
        $query = ltrim($query);
        $this->db_connect($this->dsn_select($query), true);
@@ -405,27 +405,28 @@
            $query = $this->set_limit($query, $numrows, $offset);
        }
        $params = (array) $params;
        // Because in Roundcube we mostly use queries that are
        // executed only once, we will not use prepared queries
        $pos = 0;
        $idx = 0;
        while ($pos = strpos($query, '?', $pos)) {
            if ($query[$pos+1] == '?') {  // skip escaped ?
                $pos += 2;
            }
            else {
                $val = $this->quote($params[$idx++]);
                unset($params[$idx-1]);
                $query = substr_replace($query, $val, $pos, 1);
                $pos += strlen($val);
        if (count($params)) {
            while ($pos = strpos($query, '?', $pos)) {
                if ($query[$pos+1] == '?') {  // skip escaped '?'
                    $pos += 2;
                }
                else {
                    $val = $this->quote($params[$idx++]);
                    unset($params[$idx-1]);
                    $query = substr_replace($query, $val, $pos, 1);
                    $pos += strlen($val);
                }
            }
        }
        // replace escaped ? back to normal
        $query = rtrim(strtr($query, array('??' => '?')), ';');
        // replace escaped '?' back to normal, see self::quote()
        $query = str_replace('??', '?', $query);
        $query = rtrim($query, " \t\n\r\0\x0B;");
        $this->debug($query);
@@ -456,7 +457,7 @@
    {
        $error = $this->dbh->errorInfo();
        if (empty($this->options['ignore_key_errors']) || $error[0] != '23000') {
        if (empty($this->options['ignore_key_errors']) || !in_array($error[0], array('23000', '23505'))) {
            $this->db_error = true;
            $this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]);
@@ -608,7 +609,8 @@
    {
        // get tables if not cached
        if ($this->tables === null) {
            $q = $this->query('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES ORDER BY TABLE_NAME');
            $q = $this->query('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? ORDER BY TABLE_NAME',
                array($this->db_dsnw_array['database']));
            if ($q) {
                $this->tables = $q->fetchAll(PDO::FETCH_COLUMN, 0);
@@ -630,8 +632,8 @@
     */
    public function list_cols($table)
    {
        $q = $this->query('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ?',
            array($table));
        $q = $this->query('SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?',
            array($table, $this->db_dsnw_array['database']));
        if ($q) {
            return $q->fetchAll(PDO::FETCH_COLUMN, 0);