Thomas Bruederli
2013-03-24 73be4b529609d1a53e560891eb9c1d7954b5b1ef
program/lib/Roundcube/rcube_db.php
@@ -70,7 +70,7 @@
        $driver = isset($driver_map[$driver]) ? $driver_map[$driver] : $driver;
        $class  = "rcube_db_$driver";
        if (!class_exists($class)) {
        if (!$driver || !class_exists($class)) {
            rcube::raise_error(array('code' => 600, 'type' => 'db',
                'line' => __LINE__, 'file' => __FILE__,
                'message' => "Configuration error. Unsupported database driver: $driver"),
@@ -402,6 +402,7 @@
        // destroy reference to previous result, required for SQLite driver (#1488874)
        $this->last_result = null;
        $this->db_error_msg = null;
        // send query
        $query = $this->dbh->query($query);
@@ -435,6 +436,29 @@
        }
        return 0;
    }
    /**
     * Get number of rows for a SQL query
     * If no query handle is specified, the last query will be taken as reference
     *
     * @param mixed $result Optional query handle
     * @return mixed   Number of rows or false on failure
     */
    public function num_rows($result = null)
    {
        if ($result || ($result === null && ($result = $this->last_result))) {
            // repeat query with SELECT COUNT(*) ...
            if (preg_match('/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/ims', $result->queryString, $m)) {
                $query = $this->dbh->query('SELECT COUNT(*) FROM ' . $m[1], PDO::FETCH_NUM);
                return $query ? intval($query->fetchColumn(0)) : false;
            }
            else {
                return count($result->fetchAll());
            }
        }
        return false;
    }
    /**
@@ -570,7 +594,7 @@
     * Formats input so it can be safely used in a query
     *
     * @param mixed  $input Value to quote
     * @param string $type  Type of data
     * @param string $type  Type of data (integer, bool, ident)
     *
     * @return string Quoted/converted string for use in query
     */
@@ -583,6 +607,10 @@
        if (is_null($input)) {
            return 'NULL';
        }
        if ($type == 'ident') {
            return $this->quote_identifier($input);
        }
        // create DB handle if not available
@@ -634,7 +662,7 @@
            $name[] = $start . $elem . $end;
        }
        return  implode($name, '.');
        return implode($name, '.');
    }
    /**
@@ -651,7 +679,7 @@
     * Return list of elements for use with SQL's IN clause
     *
     * @param array  $arr  Input array
     * @param string $type Type of data
     * @param string $type Type of data (integer, bool, ident)
     *
     * @return string Comma-separated list of quoted values for use in query
     */