Thomas Bruederli
2012-10-04 35cdf9771f57726bbded131d7252c3d028e18a4f
program/include/rcube_db.php
@@ -268,15 +268,15 @@
     *
     * @param int $res_id Optional query result identifier
     *
     * @return boolean True on error, False otherwise
     * @return string Error message
     */
    public function is_error($res_id = null)
    {
        if ($res_id !== null) {
            return $this->_get_result($res_id) === false;
            return $this->_get_result($res_id) === false ? $this->db_error_msg : null;
        }
        return $this->db_error;
        return $this->db_error ? $this->db_error_msg : null;
    }
    /**
@@ -388,13 +388,19 @@
        $idx = 0;
        while ($pos = strpos($query, '?', $pos)) {
            $val = $this->quote($params[$idx++]);
            unset($params[$idx-1]);
            $query = substr_replace($query, $val, $pos, 1);
            $pos += strlen($val);
            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);
            }
        }
        $query = rtrim($query, ';');
        // replace escaped ? back to normal
        $query = rtrim(strtr($query, array('??' => '?')), ';');
        $this->debug($query);
@@ -576,6 +582,10 @@
            return intval($input);
        }
        if (is_null($input)) {
            return 'NULL';
        }
        // create DB handle if not available
        if (!$this->dbh) {
            $this->db_connect('r');
@@ -587,7 +597,7 @@
                'integer' => PDO::PARAM_INT,
            );
            $type = isset($map[$type]) ? $map[$type] : PDO::PARAM_STR;
            return $this->dbh->quote($input, $type);
            return strtr($this->dbh->quote($input, $type), array('?' => '??'));  // escape ?
        }
        return 'NULL';