Changeset 1377 in subversion


Ignore:
Timestamp:
May 12, 2008 8:19:32 AM (5 years ago)
Author:
alec
Message:
  • Updated PEAR::DB package to version 1.7.13
Location:
trunk/roundcubemail
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/CHANGELOG

    r1375 r1377  
    11CHANGELOG RoundCube Webmail 
    22--------------------------- 
     3 
     42008/05/12 (alec) 
     5- Updated PEAR::DB package to version 1.7.13 
    36 
    472008/05/10 (alec) 
  • trunk/roundcubemail/program/lib/DB.php

    r12 r1377  
    1919 * @author     Tomas V.V.Cox <cox@idecnet.com> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    425425 * @author     Tomas V.V.Cox <cox@idecnet.com> 
    426426 * @author     Daniel Convissor <danielc@php.net> 
    427  * @copyright  1997-2005 The PHP Group 
     427 * @copyright  1997-2007 The PHP Group 
    428428 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    429  * @version    Release: @package_version@ 
     429 * @version    Release: 1.7.13 
    430430 * @link       http://pear.php.net/package/DB 
    431431 */ 
     
    468468        } 
    469469 
    470         @$obj =& new $classname; 
     470        @$obj = new $classname; 
    471471 
    472472        foreach ($options as $option => $value) { 
     
    545545        } 
    546546 
    547         @$obj =& new $classname; 
     547        @$obj = new $classname; 
    548548 
    549549        foreach ($options as $option => $value) { 
     
    556556        $err = $obj->connect($dsninfo, $obj->getOption('persistent')); 
    557557        if (DB::isError($err)) { 
    558             $err->addUserInfo($dsn); 
     558            if (is_array($dsn)) { 
     559                $err->addUserInfo(DB::getDSNString($dsn, true)); 
     560            } else { 
     561                $err->addUserInfo($dsn); 
     562            } 
    559563            return $err; 
    560564        } 
     
    573577    function apiVersion() 
    574578    { 
    575         return '@package_version@'; 
     579        return '1.7.13'; 
    576580    } 
    577581 
     
    626630        $manips = 'INSERT|UPDATE|DELETE|REPLACE|' 
    627631                . 'CREATE|DROP|' 
    628                 . 'LOAD DATA|SELECT .* INTO|COPY|' 
     632                . 'LOAD DATA|SELECT .* INTO .* FROM|COPY|' 
    629633                . 'ALTER|GRANT|REVOKE|' 
    630634                . 'LOCK|UNLOCK'; 
     
    809813        $parsed['protocol'] = (!empty($proto)) ? $proto : 'tcp'; 
    810814        $proto_opts = rawurldecode($proto_opts); 
     815        if (strpos($proto_opts, ':') !== false) { 
     816            list($proto_opts, $parsed['port']) = explode(':', $proto_opts); 
     817        } 
    811818        if ($parsed['protocol'] == 'tcp') { 
    812             if (strpos($proto_opts, ':') !== false) { 
    813                 list($parsed['hostspec'], 
    814                      $parsed['port']) = explode(':', $proto_opts); 
    815             } else { 
    816                 $parsed['hostspec'] = $proto_opts; 
    817             } 
     819            $parsed['hostspec'] = $proto_opts; 
    818820        } elseif ($parsed['protocol'] == 'unix') { 
    819821            $parsed['socket'] = $proto_opts; 
     
    849851 
    850852    // }}} 
     853    // {{{ getDSNString() 
     854 
     855    /** 
     856     * Returns the given DSN in a string format suitable for output. 
     857     * 
     858     * @param array|string the DSN to parse and format 
     859     * @param boolean true to hide the password, false to include it 
     860     * @return string 
     861     */ 
     862    function getDSNString($dsn, $hidePassword) { 
     863        /* Calling parseDSN will ensure that we have all the array elements 
     864         * defined, and means that we deal with strings and array in the same 
     865         * manner. */ 
     866        $dsnArray = DB::parseDSN($dsn); 
     867         
     868        if ($hidePassword) { 
     869            $dsnArray['password'] = 'PASSWORD'; 
     870        } 
     871 
     872        /* Protocol is special-cased, as using the default "tcp" along with an 
     873         * Oracle TNS connection string fails. */ 
     874        if (is_string($dsn) && strpos($dsn, 'tcp') === false && $dsnArray['protocol'] == 'tcp') { 
     875            $dsnArray['protocol'] = false; 
     876        } 
     877         
     878        // Now we just have to construct the actual string. This is ugly. 
     879        $dsnString = $dsnArray['phptype']; 
     880        if ($dsnArray['dbsyntax']) { 
     881            $dsnString .= '('.$dsnArray['dbsyntax'].')'; 
     882        } 
     883        $dsnString .= '://' 
     884                     .$dsnArray['username'] 
     885                     .':' 
     886                     .$dsnArray['password'] 
     887                     .'@' 
     888                     .$dsnArray['protocol']; 
     889        if ($dsnArray['socket']) { 
     890            $dsnString .= '('.$dsnArray['socket'].')'; 
     891        } 
     892        if ($dsnArray['protocol'] && $dsnArray['hostspec']) { 
     893            $dsnString .= '+'; 
     894        } 
     895        $dsnString .= $dsnArray['hostspec']; 
     896        if ($dsnArray['port']) { 
     897            $dsnString .= ':'.$dsnArray['port']; 
     898        } 
     899        $dsnString .= '/'.$dsnArray['database']; 
     900         
     901        /* Option handling. Unfortunately, parseDSN simply places options into 
     902         * the top-level array, so we'll first get rid of the fields defined by 
     903         * DB and see what's left. */ 
     904        unset($dsnArray['phptype'], 
     905              $dsnArray['dbsyntax'], 
     906              $dsnArray['username'], 
     907              $dsnArray['password'], 
     908              $dsnArray['protocol'], 
     909              $dsnArray['socket'], 
     910              $dsnArray['hostspec'], 
     911              $dsnArray['port'], 
     912              $dsnArray['database'] 
     913        ); 
     914        if (count($dsnArray) > 0) { 
     915            $dsnString .= '?'; 
     916            $i = 0; 
     917            foreach ($dsnArray as $key => $value) { 
     918                if (++$i > 1) { 
     919                    $dsnString .= '&'; 
     920                } 
     921                $dsnString .= $key.'='.$value; 
     922            } 
     923        } 
     924 
     925        return $dsnString; 
     926    } 
     927     
     928    // }}} 
    851929} 
    852930 
     
    861939 * @package    DB 
    862940 * @author     Stig Bakken <ssb@php.net> 
    863  * @copyright  1997-2005 The PHP Group 
     941 * @copyright  1997-2007 The PHP Group 
    864942 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    865  * @version    Release: @package_version@ 
     943 * @version    Release: 1.7.13 
    866944 * @link       http://pear.php.net/package/DB 
    867945 */ 
     
    908986 * @package    DB 
    909987 * @author     Stig Bakken <ssb@php.net> 
    910  * @copyright  1997-2005 The PHP Group 
     988 * @copyright  1997-2007 The PHP Group 
    911989 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    912  * @version    Release: @package_version@ 
     990 * @version    Release: 1.7.13 
    913991 * @link       http://pear.php.net/package/DB 
    914992 */ 
     
    10901168            $object_class = $this->fetchmode_object_class; 
    10911169        } 
    1092         if ($this->limit_from !== null) { 
     1170        if (is_null($rownum) && $this->limit_from !== null) { 
    10931171            if ($this->row_counter === null) { 
    10941172                $this->row_counter = $this->limit_from; 
     
    11221200                    $arr = (object) $arr; 
    11231201                } else { 
    1124                     $arr = &new $object_class($arr); 
     1202                    $arr = new $object_class($arr); 
    11251203                } 
    11261204            } 
     
    11721250            $object_class = $this->fetchmode_object_class; 
    11731251        } 
    1174         if ($this->limit_from !== null) { 
     1252        if (is_null($rownum) && $this->limit_from !== null) { 
    11751253            if ($this->row_counter === null) { 
    11761254                $this->row_counter = $this->limit_from; 
     
    12541332                $i++; 
    12551333            } 
    1256             return $i; 
     1334            $count = $i; 
    12571335        } else { 
    1258             return $this->dbh->numRows($this->result); 
    1259         } 
     1336            $count = $this->dbh->numRows($this->result); 
     1337        } 
     1338 
     1339        /* fbsql is checked for here because limit queries are implemented 
     1340         * using a TOP() function, which results in fbsql_num_rows still 
     1341         * returning the total number of rows that would have been returned, 
     1342         * rather than the real number. As a result, we'll just do the limit 
     1343         * calculations for fbsql in the same way as a database with emulated 
     1344         * limits. Unfortunately, we can't just do this in DB_fbsql::numRows() 
     1345         * because that only gets the result resource, rather than the full 
     1346         * DB_Result object. */ 
     1347        if (($this->dbh->features['limit'] === 'emulate' 
     1348             && $this->limit_from !== null) 
     1349            || $this->dbh->phptype == 'fbsql') { 
     1350            $limit_count = is_null($this->limit_count) ? $count : $this->limit_count; 
     1351            if ($count < $this->limit_from) { 
     1352                $count = 0; 
     1353            } elseif ($count < ($this->limit_from + $limit_count)) { 
     1354                $count -= $this->limit_from; 
     1355            } else { 
     1356                $count = $limit_count; 
     1357            } 
     1358        } 
     1359 
     1360        return $count; 
    12601361    } 
    12611362 
     
    13501451 * @package    DB 
    13511452 * @author     Stig Bakken <ssb@php.net> 
    1352  * @copyright  1997-2005 The PHP Group 
     1453 * @copyright  1997-2007 The PHP Group 
    13531454 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    1354  * @version    Release: @package_version@ 
     1455 * @version    Release: 1.7.13 
    13551456 * @link       http://pear.php.net/package/DB 
    13561457 * @see        DB_common::setFetchMode() 
  • trunk/roundcubemail/program/lib/DB/common.php

    r12 r1377  
    1919 * @author     Tomas V.V. Cox <cox@idecnet.com> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    4141 * @author     Tomas V.V. Cox <cox@idecnet.com> 
    4242 * @author     Daniel Convissor <danielc@php.net> 
    43  * @copyright  1997-2005 The PHP Group 
     43 * @copyright  1997-2007 The PHP Group 
    4444 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    45  * @version    Release: @package_version@ 
     45 * @version    Release: 1.7.13 
    4646 * @link       http://pear.php.net/package/DB 
    4747 */ 
     
    121121     */ 
    122122    var $prepared_queries = array(); 
     123 
     124    /** 
     125     * Flag indicating that the last query was a manipulation query. 
     126     * @access protected 
     127     * @var boolean 
     128     */ 
     129    var $_last_query_manip = false; 
     130 
     131    /** 
     132     * Flag indicating that the next query <em>must</em> be a manipulation 
     133     * query. 
     134     * @access protected 
     135     * @var boolean 
     136     */ 
     137    var $_next_query_manip = false; 
    123138 
    124139 
     
    425440    function quoteSmart($in) 
    426441    { 
    427         if (is_int($in) || is_double($in)) { 
     442        if (is_int($in)) { 
    428443            return $in; 
     444        } elseif (is_float($in)) { 
     445            return $this->quoteFloat($in); 
    429446        } elseif (is_bool($in)) { 
    430             return $in ? 1 : 0; 
     447            return $this->quoteBoolean($in); 
    431448        } elseif (is_null($in)) { 
    432449            return 'NULL'; 
    433450        } else { 
     451            if ($this->dbsyntax == 'access' 
     452                && preg_match('/^#.+#$/', $in)) 
     453            { 
     454                return $this->escapeSimple($in); 
     455            } 
    434456            return "'" . $this->escapeSimple($in) . "'"; 
    435457        } 
    436458    } 
    437459 
     460    // }}} 
     461    // {{{ quoteBoolean() 
     462 
     463    /** 
     464     * Formats a boolean value for use within a query in a locale-independent 
     465     * manner. 
     466     * 
     467     * @param boolean the boolean value to be quoted. 
     468     * @return string the quoted string. 
     469     * @see DB_common::quoteSmart() 
     470     * @since Method available since release 1.7.8. 
     471     */ 
     472    function quoteBoolean($boolean) { 
     473        return $boolean ? '1' : '0'; 
     474    } 
     475      
     476    // }}} 
     477    // {{{ quoteFloat() 
     478 
     479    /** 
     480     * Formats a float value for use within a query in a locale-independent 
     481     * manner. 
     482     * 
     483     * @param float the float value to be quoted. 
     484     * @return string the quoted string. 
     485     * @see DB_common::quoteSmart() 
     486     * @since Method available since release 1.7.8. 
     487     */ 
     488    function quoteFloat($float) { 
     489        return "'".$this->escapeSimple(str_replace(',', '.', strval(floatval($float))))."'"; 
     490    } 
     491      
    438492    // }}} 
    439493    // {{{ escapeSimple() 
     
    838892            return $sth; 
    839893        } 
    840         $ret =& $this->execute($sth, array_values($fields_values)); 
     894        $ret = $this->execute($sth, array_values($fields_values)); 
    841895        $this->freePrepared($sth); 
    842896        return $ret; 
     
    932986     *     'filename.txt' 
    933987     * ); 
    934      * $res =& $db->execute($sth, $data); 
     988     * $res = $db->execute($sth, $data); 
    935989     * </code> 
    936990     * 
     
    9611015            return $result; 
    9621016        } else { 
    963             $tmp =& new DB_result($this, $result); 
     1017            $tmp = new DB_result($this, $result); 
    9641018            return $tmp; 
    9651019        } 
     
    10421096    { 
    10431097        foreach ($data as $value) { 
    1044             $res =& $this->execute($stmt, $value); 
     1098            $res = $this->execute($stmt, $value); 
    10451099            if (DB::isError($res)) { 
    10461100                return $res; 
     
    11551209                return $sth; 
    11561210            } 
    1157             $ret =& $this->execute($sth, $params); 
     1211            $ret = $this->execute($sth, $params); 
    11581212            $this->freePrepared($sth, false); 
    11591213            return $ret; 
     
    11641218                return $result; 
    11651219            } else { 
    1166                 $tmp =& new DB_result($this, $result); 
     1220                $tmp = new DB_result($this, $result); 
    11671221                return $tmp; 
    11681222            } 
     
    11951249            return $query; 
    11961250        } 
    1197         $result =& $this->query($query, $params); 
     1251        $result = $this->query($query, $params); 
    11981252        if (is_a($result, 'DB_result')) { 
    11991253            $result->setOption('limit_from', $from); 
     
    12301284                return $sth; 
    12311285            } 
    1232             $res =& $this->execute($sth, $params); 
     1286            $res = $this->execute($sth, $params); 
    12331287            $this->freePrepared($sth); 
    12341288        } else { 
    1235             $res =& $this->query($query); 
     1289            $res = $this->query($query); 
    12361290        } 
    12371291 
     
    12941348                return $sth; 
    12951349            } 
    1296             $res =& $this->execute($sth, $params); 
     1350            $res = $this->execute($sth, $params); 
    12971351            $this->freePrepared($sth); 
    12981352        } else { 
    1299             $res =& $this->query($query); 
     1353            $res = $this->query($query); 
    13001354        } 
    13011355 
     
    13451399            } 
    13461400 
    1347             $res =& $this->execute($sth, $params); 
     1401            $res = $this->execute($sth, $params); 
    13481402            $this->freePrepared($sth); 
    13491403        } else { 
    1350             $res =& $this->query($query); 
     1404            $res = $this->query($query); 
    13511405        } 
    13521406 
     
    13611415        } else { 
    13621416            if (!array_key_exists($col, $row)) { 
    1363                 $ret =& $this->raiseError(DB_ERROR_NOSUCHFIELD); 
     1417                $ret = $this->raiseError(DB_ERROR_NOSUCHFIELD); 
    13641418            } else { 
    13651419                $ret = array($row[$col]); 
     
    14771531            } 
    14781532 
    1479             $res =& $this->execute($sth, $params); 
     1533            $res = $this->execute($sth, $params); 
    14801534            $this->freePrepared($sth); 
    14811535        } else { 
    1482             $res =& $this->query($query); 
     1536            $res = $this->query($query); 
    14831537        } 
    14841538 
     
    14921546 
    14931547        if ($cols < 2) { 
    1494             $tmp =& $this->raiseError(DB_ERROR_TRUNCATED); 
     1548            $tmp = $this->raiseError(DB_ERROR_TRUNCATED); 
    14951549            return $tmp; 
    14961550        } 
     
    16041658            } 
    16051659 
    1606             $res =& $this->execute($sth, $params); 
     1660            $res = $this->execute($sth, $params); 
    16071661            $this->freePrepared($sth); 
    16081662        } else { 
    1609             $res =& $this->query($query); 
     1663            $res = $this->query($query); 
    16101664        } 
    16111665 
     
    16281682 
    16291683        if (DB::isError($row)) { 
    1630             $tmp =& $this->raiseError($row); 
     1684            $tmp = $this->raiseError($row); 
    16311685            return $tmp; 
    16321686        } 
     
    21042158 
    21052159    // }}} 
     2160    // {{{ nextQueryIsManip() 
     2161 
     2162    /** 
     2163     * Sets (or unsets) a flag indicating that the next query will be a 
     2164     * manipulation query, regardless of the usual DB::isManip() heuristics. 
     2165     * 
     2166     * @param boolean true to set the flag overriding the isManip() behaviour, 
     2167     * false to clear it and fall back onto isManip() 
     2168     * 
     2169     * @return void 
     2170     * 
     2171     * @access public 
     2172     */ 
     2173    function nextQueryIsManip($manip) 
     2174    { 
     2175        $this->_next_query_manip = $manip; 
     2176    } 
     2177 
     2178    // }}} 
     2179    // {{{ _checkManip() 
     2180 
     2181    /** 
     2182     * Checks if the given query is a manipulation query. This also takes into 
     2183     * account the _next_query_manip flag and sets the _last_query_manip flag 
     2184     * (and resets _next_query_manip) according to the result. 
     2185     * 
     2186     * @param string The query to check. 
     2187     * 
     2188     * @return boolean true if the query is a manipulation query, false 
     2189     * otherwise 
     2190     * 
     2191     * @access protected 
     2192     */ 
     2193    function _checkManip($query) 
     2194    { 
     2195        if ($this->_next_query_manip || DB::isManip($query)) { 
     2196            $this->_last_query_manip = true; 
     2197        } else { 
     2198            $this->_last_query_manip = false; 
     2199        } 
     2200        $this->_next_query_manip = false; 
     2201        return $this->_last_query_manip; 
     2202        $manip = $this->_next_query_manip; 
     2203    } 
     2204 
     2205    // }}} 
    21062206    // {{{ _rtrimArrayValues() 
    21072207 
  • trunk/roundcubemail/program/lib/DB/dbase.php

    r12 r1377  
    1919 * @author     Tomas V.V. Cox <cox@idecnet.com> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    4040 * @author     Tomas V.V. Cox <cox@idecnet.com> 
    4141 * @author     Daniel Convissor <danielc@php.net> 
    42  * @copyright  1997-2005 The PHP Group 
     42 * @copyright  1997-2007 The PHP Group 
    4343 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    44  * @version    Release: @package_version@ 
     44 * @version    Release: 1.7.13 
    4545 * @link       http://pear.php.net/package/DB 
    4646 */ 
     
    189189     * ); 
    190190     * 
    191      * $db =& DB::connect($dsn, $options); 
     191     * $db = DB::connect($dsn, $options); 
    192192     * if (PEAR::isError($db)) { 
    193193     *     die($db->getMessage()); 
     
    215215         * is the only way to find errors from the dbase extension. 
    216216         */ 
    217         ini_set('track_errors', 1); 
     217        @ini_set('track_errors', 1); 
    218218        $php_errormsg = ''; 
    219219 
     
    274274        // emulate result resources 
    275275        $this->res_row[(int)$this->result] = 0; 
    276         $tmp =& new DB_result($this, $this->result++); 
     276        $tmp = new DB_result($this, $this->result++); 
    277277        return $tmp; 
    278278    } 
     
    327327 
    328328    // }}} 
     329    // {{{ freeResult() 
     330 
     331    /** 
     332     * Deletes the result set and frees the memory occupied by the result set. 
     333     * 
     334     * This method is a no-op for dbase, as there aren't result resources in 
     335     * the same sense as most other database backends. 
     336     * 
     337     * @param resource $result  PHP's query result resource 
     338     * 
     339     * @return bool  TRUE on success, FALSE if $result is invalid 
     340     * 
     341     * @see DB_result::free() 
     342     */ 
     343    function freeResult($result) 
     344    { 
     345        return true; 
     346    } 
     347 
     348    // }}} 
    329349    // {{{ numCols() 
    330350 
     
    369389 
    370390    // }}} 
    371     // {{{ quoteSmart() 
    372  
    373     /** 
    374      * Formats input so it can be safely used in a query 
    375      * 
    376      * @param mixed $in  the data to be formatted 
    377      * 
    378      * @return mixed  the formatted data.  The format depends on the input's 
    379      *                 PHP type: 
    380      *                 + null = the string <samp>NULL</samp> 
    381      *                 + boolean = <samp>T</samp> if true or 
    382      *                   <samp>F</samp> if false.  Use the <kbd>Logical</kbd> 
    383      *                   data type. 
    384      *                 + integer or double = the unquoted number 
    385      *                 + other (including strings and numeric strings) = 
    386      *                   the data with single quotes escaped by preceeding 
    387      *                   single quotes then the whole string is encapsulated 
    388      *                   between single quotes 
    389      * 
     391    // {{{ quoteBoolean() 
     392 
     393    /** 
     394     * Formats a boolean value for use within a query in a locale-independent 
     395     * manner. 
     396     * 
     397     * @param boolean the boolean value to be quoted. 
     398     * @return string the quoted string. 
    390399     * @see DB_common::quoteSmart() 
    391      * @since Method available since Release 1.6.0 
    392      */ 
    393     function quoteSmart($in) 
    394     { 
    395         if (is_int($in) || is_double($in)) { 
    396             return $in; 
    397         } elseif (is_bool($in)) { 
    398             return $in ? 'T' : 'F'; 
    399         } elseif (is_null($in)) { 
    400             return 'NULL'; 
    401         } else { 
    402             return "'" . $this->escapeSimple($in) . "'"; 
    403         } 
    404     } 
    405  
     400     * @since Method available since release 1.7.8. 
     401     */ 
     402    function quoteBoolean($boolean) { 
     403        return $boolean ? 'T' : 'F'; 
     404    } 
     405      
    406406    // }}} 
    407407    // {{{ tableInfo() 
  • trunk/roundcubemail/program/lib/DB/fbsql.php

    r12 r1377  
    1919 * @author     Frank M. Kromann <frank@frontbase.com> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    4040 * @author     Frank M. Kromann <frank@frontbase.com> 
    4141 * @author     Daniel Convissor <danielc@php.net> 
    42  * @copyright  1997-2005 The PHP Group 
     42 * @copyright  1997-2007 The PHP Group 
    4343 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    44  * @version    Release: @package_version@ 
     44 * @version    Release: 1.7.13 
    4545 * @link       http://pear.php.net/package/DB 
    4646 * @since      Class functional since Release 1.7.0 
     
    172172                                                      $params); 
    173173        } else { 
    174             ini_set('track_errors', 1); 
     174            @ini_set('track_errors', 1); 
    175175            $this->connection = @call_user_func_array($connect_function, 
    176176                                                      $params); 
    177             ini_set('track_errors', $ini); 
     177            @ini_set('track_errors', $ini); 
    178178        } 
    179179 
     
    230230        // Determine which queries that should return data, and which 
    231231        // should return an error code only. 
    232         if (DB::isManip($query)) { 
     232        if ($this->_checkManip($query)) { 
    233233            return DB_OK; 
    234234        } 
     
    321321    function freeResult($result) 
    322322    { 
    323         return @fbsql_free_result($result); 
     323        return is_resource($result) ? fbsql_free_result($result) : false; 
    324324    } 
    325325 
     
    354354    function commit() 
    355355    { 
    356         @fbsql_commit(); 
     356        @fbsql_commit($this->connection); 
    357357    } 
    358358 
     
    367367    function rollback() 
    368368    { 
    369         @fbsql_rollback(); 
     369        @fbsql_rollback($this->connection); 
    370370    } 
    371371 
     
    432432    function affectedRows() 
    433433    { 
    434         if (DB::isManip($this->last_query)) { 
     434        if ($this->_last_query_manip) { 
    435435            $result = @fbsql_affected_rows($this->connection); 
    436436        } else { 
     
    544544    function modifyLimitQuery($query, $from, $count, $params = array()) 
    545545    { 
    546         if (DB::isManip($query)) { 
     546        if (DB::isManip($query) || $this->_next_query_manip) { 
    547547            return preg_replace('/^([\s(])*SELECT/i', 
    548548                                "\\1SELECT TOP($count)", $query); 
     
    554554 
    555555    // }}} 
    556     // {{{ quoteSmart() 
    557  
    558     /** 
    559      * Formats input so it can be safely used in a query 
    560      * 
    561      * @param mixed $in  the data to be formatted 
    562      * 
    563      * @return mixed  the formatted data.  The format depends on the input's 
    564      *                 PHP type: 
    565      *                 + null = the string <samp>NULL</samp> 
    566      *                 + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp> 
    567      *                 + integer or double = the unquoted number 
    568      *                 + other (including strings and numeric strings) = 
    569      *                   the data escaped according to FrontBase's settings 
    570      *                   then encapsulated between single quotes 
    571      * 
     556    // {{{ quoteBoolean() 
     557 
     558    /** 
     559     * Formats a boolean value for use within a query in a locale-independent 
     560     * manner. 
     561     * 
     562     * @param boolean the boolean value to be quoted. 
     563     * @return string the quoted string. 
    572564     * @see DB_common::quoteSmart() 
    573      * @since Method available since Release 1.6.0 
    574      */ 
    575     function quoteSmart($in) 
    576     { 
    577         if (is_int($in) || is_double($in)) { 
    578             return $in; 
    579         } elseif (is_bool($in)) { 
    580             return $in ? 'TRUE' : 'FALSE'; 
    581         } elseif (is_null($in)) { 
    582             return 'NULL'; 
    583         } else { 
    584             return "'" . $this->escapeSimple($in) . "'"; 
    585         } 
    586     } 
    587  
     565     * @since Method available since release 1.7.8. 
     566     */ 
     567    function quoteBoolean($boolean) { 
     568        return $boolean ? 'TRUE' : 'FALSE'; 
     569    } 
     570      
     571    // }}} 
     572    // {{{ quoteFloat() 
     573 
     574    /** 
     575     * Formats a float value for use within a query in a locale-independent 
     576     * manner. 
     577     * 
     578     * @param float the float value to be quoted. 
     579     * @return string the quoted string. 
     580     * @see DB_common::quoteSmart() 
     581     * @since Method available since release 1.7.8. 
     582     */ 
     583    function quoteFloat($float) { 
     584        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); 
     585    } 
     586      
    588587    // }}} 
    589588    // {{{ fbsqlRaiseError() 
  • trunk/roundcubemail/program/lib/DB/ibase.php

    r12 r1377  
    2222 * @author     Sterling Hughes <sterling@php.net> 
    2323 * @author     Daniel Convissor <danielc@php.net> 
    24  * @copyright  1997-2005 The PHP Group 
     24 * @copyright  1997-2007 The PHP Group 
    2525 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2626 * @version    CVS: $Id$ 
     
    4848 * @author     Sterling Hughes <sterling@php.net> 
    4949 * @author     Daniel Convissor <danielc@php.net> 
    50  * @copyright  1997-2005 The PHP Group 
     50 * @copyright  1997-2007 The PHP Group 
    5151 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    52  * @version    Release: @package_version@ 
     52 * @version    Release: 1.7.13 
    5353 * @link       http://pear.php.net/package/DB 
    5454 * @since      Class became stable in Release 1.7.0 
     
    124124        -803 => DB_ERROR_CONSTRAINT, 
    125125        -804 => DB_ERROR_VALUE_COUNT_ON_ROW, 
     126        // -902 =>  // Covers too many errors, need to use regex on msg 
    126127        -904 => DB_ERROR_CONNECT_FAILED, 
    127128        -922 => DB_ERROR_NOSUCHDB, 
     
    276277    function simpleQuery($query) 
    277278    { 
    278         $ismanip = DB::isManip($query); 
     279        $ismanip = $this->_checkManip($query); 
    279280        $this->last_query = $query; 
    280281        $query = $this->modifyQuery($query); 
     
    413414    function freeResult($result) 
    414415    { 
    415         return @ibase_free_result($result); 
     416        return is_resource($result) ? ibase_free_result($result) : false; 
    416417    } 
    417418 
     
    421422    function freeQuery($query) 
    422423    { 
    423         @ibase_free_query($query); 
    424         return true; 
     424        return is_resource($query) ? ibase_free_query($query) : false; 
    425425    } 
    426426 
     
    522522        $newquery = $this->modifyQuery($newquery); 
    523523        $stmt = @ibase_prepare($this->connection, $newquery); 
    524         $this->prepare_types[(int)$stmt] = $types; 
    525         $this->manip_query[(int)$stmt]   = DB::isManip($query); 
     524 
     525        if ($stmt === false) { 
     526            $stmt = $this->ibaseRaiseError(); 
     527        } else { 
     528            $this->prepare_types[(int)$stmt] = $types; 
     529            $this->manip_query[(int)$stmt]   = DB::isManip($query); 
     530        } 
     531 
    526532        return $stmt; 
    527533    } 
     
    548554        $this->last_parameters = $data; 
    549555 
    550         $types =& $this->prepare_types[(int)$stmt]; 
     556        $types = $this->prepare_types[(int)$stmt]; 
    551557        if (count($types) != count($data)) { 
    552             $tmp =& $this->raiseError(DB_ERROR_MISMATCH); 
     558            $tmp = $this->raiseError(DB_ERROR_MISMATCH); 
    553559            return $tmp; 
    554560        } 
     
    569575                $fp = @fopen($data[$key], 'rb'); 
    570576                if (!$fp) { 
    571                     $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION); 
     577                    $tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION); 
    572578                    return $tmp; 
    573579                } 
     
    582588        $res = call_user_func_array('ibase_execute', $data); 
    583589        if (!$res) { 
    584             $tmp =& $this->ibaseRaiseError(); 
     590            $tmp = $this->ibaseRaiseError(); 
    585591            return $tmp; 
    586592        } 
     
    590596        }*/ 
    591597        $this->last_stmt = $stmt; 
    592         if ($this->manip_query[(int)$stmt]) { 
     598        if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) { 
     599            $this->_last_query_manip = true; 
     600            $this->_next_query_manip = false; 
    593601            $tmp = DB_OK; 
    594602        } else { 
    595             $tmp =& new DB_result($this, $res); 
     603            $this->_last_query_manip = false; 
     604            $tmp = new DB_result($this, $res); 
    596605        } 
    597606        return $tmp; 
     
    699708        do { 
    700709            $this->pushErrorHandling(PEAR_ERROR_RETURN); 
    701             $result =& $this->query("SELECT GEN_ID(${sqn}, 1) " 
     710            $result = $this->query("SELECT GEN_ID(${sqn}, 1) " 
    702711                                   . 'FROM RDB$GENERATORS ' 
    703712                                   . "WHERE RDB\$GENERATOR_NAME='${sqn}'"); 
     
    857866            $errno = $this->errorCode($this->errorNative()); 
    858867        } 
    859         $tmp =& $this->raiseError($errno, null, null, null, @ibase_errmsg()); 
     868        $tmp = $this->raiseError($errno, null, null, null, @ibase_errmsg()); 
    860869        return $tmp; 
    861870    } 
     
    926935                '/arithmetic exception, numeric overflow, or string truncation/i' 
    927936                    => DB_ERROR_INVALID, 
     937                '/feature is not supported/i' 
     938                    => DB_ERROR_NOT_CAPABLE, 
    928939            ); 
    929940        } 
  • trunk/roundcubemail/program/lib/DB/ifx.php

    r12 r1377  
    1919 * @author     Tomas V.V.Cox <cox@idecnet.com> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    4747 * @author     Tomas V.V.Cox <cox@idecnet.com> 
    4848 * @author     Daniel Convissor <danielc@php.net> 
    49  * @copyright  1997-2005 The PHP Group 
     49 * @copyright  1997-2007 The PHP Group 
    5050 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    51  * @version    Release: @package_version@ 
     51 * @version    Release: 1.7.13 
    5252 * @link       http://pear.php.net/package/DB 
    5353 */ 
     
    102102        '-239'    => DB_ERROR_CONSTRAINT, 
    103103        '-253'    => DB_ERROR_SYNTAX, 
     104        '-268'    => DB_ERROR_CONSTRAINT, 
    104105        '-292'    => DB_ERROR_CONSTRAINT_NOT_NULL, 
    105106        '-310'    => DB_ERROR_ALREADY_EXISTS, 
     
    114115        '-692'    => DB_ERROR_CONSTRAINT, 
    115116        '-703'    => DB_ERROR_CONSTRAINT_NOT_NULL, 
     117        '-1202'   => DB_ERROR_DIVZERO, 
    116118        '-1204'   => DB_ERROR_INVALID_DATE, 
    117119        '-1205'   => DB_ERROR_INVALID_DATE, 
     
    244246    function simpleQuery($query) 
    245247    { 
    246         $ismanip = DB::isManip($query); 
     248        $ismanip = $this->_checkManip($query); 
    247249        $this->last_query = $query; 
    248250        $this->affected   = null; 
    249         if (preg_match('/(SELECT)/i', $query)) {    //TESTME: Use !DB::isManip()? 
     251        if (preg_match('/(SELECT|EXECUTE)/i', $query)) {    //TESTME: Use !DB::isManip()? 
    250252            // the scroll is needed for fetching absolute row numbers 
    251253            // in a select query result 
     
    269271        // Determine which queries should return data, and which 
    270272        // should return an error code only. 
    271         if (preg_match('/(SELECT)/i', $query)) { 
     273        if (preg_match('/(SELECT|EXECUTE)/i', $query)) { 
    272274            return $result; 
    273275        } 
     
    310312    function affectedRows() 
    311313    { 
    312         if (DB::isManip($this->last_query)) { 
     314        if ($this->_last_query_manip) { 
    313315            return $this->affected; 
    314316        } else { 
     
    421423    function freeResult($result) 
    422424    { 
    423         return @ifx_free_result($result); 
     425        return is_resource($result) ? ifx_free_result($result) : false; 
    424426    } 
    425427 
  • trunk/roundcubemail/program/lib/DB/msql.php

    r12 r1377  
    2222 * @package    DB 
    2323 * @author     Daniel Convissor <danielc@php.net> 
    24  * @copyright  1997-2005 The PHP Group 
     24 * @copyright  1997-2007 The PHP Group 
    2525 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2626 * @version    CVS: $Id$ 
     
    4646 * @package    DB 
    4747 * @author     Daniel Convissor <danielc@php.net> 
    48  * @copyright  1997-2005 The PHP Group 
     48 * @copyright  1997-2007 The PHP Group 
    4949 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    50  * @version    Release: @package_version@ 
     50 * @version    Release: 1.7.13 
    5151 * @link       http://pear.php.net/package/DB 
    5252 * @since      Class not functional until Release 1.7.0 
     
    154154     * ); 
    155155     *  
    156      * $db =& DB::connect($dsn, $options); 
     156     * $db = DB::connect($dsn, $options); 
    157157     * if (PEAR::isError($db)) { 
    158158     *     die($db->getMessage()); 
     
    191191                                                      $params); 
    192192        } else { 
    193             ini_set('track_errors', 1); 
     193            @ini_set('track_errors', 1); 
    194194            $this->connection = @call_user_func_array($connect_function, 
    195195                                                      $params); 
    196             ini_set('track_errors', $ini); 
     196            @ini_set('track_errors', $ini); 
    197197        } 
    198198 
     
    252252        // Determine which queries that should return data, and which 
    253253        // should return an error code only. 
    254         if (DB::isManip($query)) { 
     254        if ($this->_checkManip($query)) { 
    255255            $this->_result = $result; 
    256256            return DB_OK; 
     
    351351    function freeResult($result) 
    352352    { 
    353         return @msql_free_result($result); 
     353        return is_resource($result) ? msql_free_result($result) : false; 
    354354    } 
    355355 
     
    444444        do { 
    445445            $this->pushErrorHandling(PEAR_ERROR_RETURN); 
    446             $result =& $this->query("SELECT _seq FROM ${seqname}"); 
     446            $result = $this->query("SELECT _seq FROM ${seqname}"); 
    447447            $this->popErrorHandling(); 
    448448            if ($ondemand && DB::isError($result) && 
     
    532532 
    533533    // }}} 
     534    // {{{ quoteFloat() 
     535 
     536    /** 
     537     * Formats a float value for use within a query in a locale-independent 
     538     * manner. 
     539     * 
     540     * @param float the float value to be quoted. 
     541     * @return string the quoted string. 
     542     * @see DB_common::quoteSmart() 
     543     * @since Method available since release 1.7.8. 
     544     */ 
     545    function quoteFloat($float) { 
     546        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); 
     547    } 
     548      
     549    // }}} 
    534550    // {{{ escapeSimple() 
    535551 
     
    599615    { 
    600616        static $error_regexps; 
     617         
     618        // PHP 5.2+ prepends the function name to $php_errormsg, so we need 
     619        // this hack to work around it, per bug #9599. 
     620        $errormsg = preg_replace('/^msql[a-z_]+\(\): /', '', $errormsg); 
     621 
    601622        if (!isset($error_regexps)) { 
    602623            $error_regexps = array( 
  • trunk/roundcubemail/program/lib/DB/mssql.php

    r12 r1377  
    1919 * @author     Sterling Hughes <sterling@php.net> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    3636 * These methods overload the ones declared in DB_common. 
    3737 * 
     38 * DB's mssql driver is only for Microsfoft SQL Server databases. 
     39 * 
     40 * If you're connecting to a Sybase database, you MUST specify "sybase" 
     41 * as the "phptype" in the DSN. 
     42 * 
     43 * This class only works correctly if you have compiled PHP using 
     44 * --with-mssql=[dir_to_FreeTDS]. 
     45 * 
    3846 * @category   Database 
    3947 * @package    DB 
    4048 * @author     Sterling Hughes <sterling@php.net> 
    4149 * @author     Daniel Convissor <danielc@php.net> 
    42  * @copyright  1997-2005 The PHP Group 
     50 * @copyright  1997-2007 The PHP Group 
    4351 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    44  * @version    Release: @package_version@ 
     52 * @version    Release: 1.7.13 
    4553 * @link       http://pear.php.net/package/DB 
    4654 */ 
     
    9098    // XXX Add here error codes ie: 'S100E' => DB_ERROR_SYNTAX 
    9199    var $errorcode_map = array( 
     100        102   => DB_ERROR_SYNTAX, 
    92101        110   => DB_ERROR_VALUE_COUNT_ON_ROW, 
    93102        155   => DB_ERROR_NOSUCHFIELD, 
     103        156   => DB_ERROR_SYNTAX, 
    94104        170   => DB_ERROR_SYNTAX, 
    95105        207   => DB_ERROR_NOSUCHFIELD, 
    96106        208   => DB_ERROR_NOSUCHTABLE, 
    97107        245   => DB_ERROR_INVALID_NUMBER, 
     108        319   => DB_ERROR_SYNTAX, 
     109        321   => DB_ERROR_NOSUCHFIELD, 
     110        325   => DB_ERROR_SYNTAX, 
     111        336   => DB_ERROR_SYNTAX, 
    98112        515   => DB_ERROR_CONSTRAINT_NOT_NULL, 
    99113        547   => DB_ERROR_CONSTRAINT, 
     114        1018  => DB_ERROR_SYNTAX, 
     115        1035  => DB_ERROR_SYNTAX, 
    100116        1913  => DB_ERROR_ALREADY_EXISTS, 
     117        2209  => DB_ERROR_SYNTAX, 
     118        2223  => DB_ERROR_SYNTAX, 
     119        2248  => DB_ERROR_SYNTAX, 
     120        2256  => DB_ERROR_SYNTAX, 
     121        2257  => DB_ERROR_SYNTAX, 
    101122        2627  => DB_ERROR_CONSTRAINT, 
    102123        2714  => DB_ERROR_ALREADY_EXISTS, 
     124        3607  => DB_ERROR_DIVZERO, 
    103125        3701  => DB_ERROR_NOSUCHTABLE, 
     126        7630  => DB_ERROR_SYNTAX, 
    104127        8134  => DB_ERROR_DIVZERO, 
     128        9303  => DB_ERROR_SYNTAX, 
     129        9317  => DB_ERROR_SYNTAX, 
     130        9318  => DB_ERROR_SYNTAX, 
     131        9331  => DB_ERROR_SYNTAX, 
     132        9332  => DB_ERROR_SYNTAX, 
     133        15253 => DB_ERROR_SYNTAX, 
    105134    ); 
    106135 
     
    245274    function simpleQuery($query) 
    246275    { 
    247         $ismanip = DB::isManip($query); 
     276        $ismanip = $this->_checkManip($query); 
    248277        $this->last_query = $query; 
    249278        if (!@mssql_select_db($this->_db, $this->connection)) { 
     
    317346        } 
    318347        if ($fetchmode & DB_FETCHMODE_ASSOC) { 
    319             $arr = @mssql_fetch_array($result, MSSQL_ASSOC); 
     348            $arr = @mssql_fetch_assoc($result); 
    320349            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { 
    321350                $arr = array_change_key_case($arr, CASE_LOWER); 
     
    354383    function freeResult($result) 
    355384    { 
    356         return @mssql_free_result($result); 
     385        return is_resource($result) ? mssql_free_result($result) : false; 
    357386    } 
    358387 
     
    484513    function affectedRows() 
    485514    { 
    486         if (DB::isManip($this->last_query)) { 
     515        if ($this->_last_query_manip) { 
    487516            $res = @mssql_query('select @@rowcount', $this->connection); 
    488517            if (!$res) { 
     
    538567                } 
    539568            } elseif (!DB::isError($result)) { 
    540                 $result =& $this->query("SELECT @@IDENTITY FROM $seqname"); 
     569                $result = $this->query("SELECT IDENT_CURRENT('$seqname')"); 
     570                if (DB::isError($result)) { 
     571                    /* Fallback code for MS SQL Server 7.0, which doesn't have 
     572                     * IDENT_CURRENT. This is *not* safe for concurrent 
     573                     * requests, and really, if you're using it, you're in a 
     574                     * world of hurt. Nevertheless, it's here to ensure BC. See 
     575                     * bug #181 for the gory details.*/ 
     576                    $result = $this->query("SELECT @@IDENTITY FROM $seqname"); 
     577                } 
    541578                $repeat = 0; 
    542579            } else { 
     
    746783 
    747784        for ($i = 0; $i < $count; $i++) { 
     785            if ($got_string) { 
     786                $flags = $this->_mssql_field_flags($result, 
     787                        @mssql_field_name($id, $i)); 
     788                if (DB::isError($flags)) { 
     789                    return $flags; 
     790                } 
     791            } else { 
     792                $flags = ''; 
     793            } 
     794 
    748795            $res[$i] = array( 
    749796                'table' => $got_string ? $case_func($result) : '', 
     
    751798                'type'  => @mssql_field_type($id, $i), 
    752799                'len'   => @mssql_field_length($id, $i), 
    753                 // We only support flags for table 
    754                 'flags' => $got_string 
    755                            ? $this->_mssql_field_flags($result, 
    756                                                        @mssql_field_name($id, $i)) 
    757                            : '', 
     800                'flags' => $flags, 
    758801            ); 
    759802            if ($mode & DB_TABLEINFO_ORDER) { 
     
    806849 
    807850            // get unique and primary keys 
    808             $res = $this->getAll("EXEC SP_HELPINDEX[$table]", DB_FETCHMODE_ASSOC); 
     851            $res = $this->getAll("EXEC SP_HELPINDEX $table", DB_FETCHMODE_ASSOC); 
     852            if (DB::isError($res)) { 
     853                return $res; 
     854            } 
    809855 
    810856            foreach ($res as $val) { 
     
    829875 
    830876            // get auto_increment, not_null and timestamp 
    831             $res = $this->getAll("EXEC SP_COLUMNS[$table]", DB_FETCHMODE_ASSOC); 
     877            $res = $this->getAll("EXEC SP_COLUMNS $table", DB_FETCHMODE_ASSOC); 
     878            if (DB::isError($res)) { 
     879                return $res; 
     880            } 
    832881 
    833882            foreach ($res as $val) { 
  • trunk/roundcubemail/program/lib/DB/mysql.php

    r12 r1377  
    1919 * @author     Stig Bakken <ssb@php.net> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    4040 * @author     Stig Bakken <ssb@php.net> 
    4141 * @author     Daniel Convissor <danielc@php.net> 
    42  * @copyright  1997-2005 The PHP Group 
     42 * @copyright  1997-2007 The PHP Group 
    4343 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    44  * @version    Release: @package_version@ 
     44 * @version    Release: 1.7.13 
    4545 * @link       http://pear.php.net/package/DB 
    4646 */ 
     
    112112        1216 => DB_ERROR_CONSTRAINT, 
    113113        1217 => DB_ERROR_CONSTRAINT, 
     114        1356 => DB_ERROR_DIVZERO, 
     115        1451 => DB_ERROR_CONSTRAINT, 
     116        1452 => DB_ERROR_CONSTRAINT, 
    114117    ); 
    115118 
     
    237240                                                      $params); 
    238241        } else { 
    239             ini_set('track_errors', 1); 
     242            @ini_set('track_errors', 1); 
    240243            $this->connection = @call_user_func_array($connect_function, 
    241244                                                      $params); 
    242             ini_set('track_errors', $ini); 
     245            @ini_set('track_errors', $ini); 
    243246        } 
    244247 
     
    298301    function simpleQuery($query) 
    299302    { 
    300         $ismanip = DB::isManip($query); 
     303        $ismanip = $this->_checkManip($query); 
    301304        $this->last_query = $query; 
    302305        $query = $this->modifyQuery($query); 
     
    420423    function freeResult($result) 
    421424    { 
    422         return @mysql_free_result($result); 
     425        return is_resource($result) ? mysql_free_result($result) : false; 
    423426    } 
    424427 
     
    556559    function affectedRows() 
    557560    { 
    558         if (DB::isManip($this->last_query)) { 
     561        if ($this->_last_query_manip) { 
    559562            return @mysql_affected_rows($this->connection); 
    560563        } else { 
     
    753756    /** 
    754757     * Quotes a string so it can be safely used as a table or column name 
    755      * 
    756      * MySQL can't handle the backtick character (<kbd>`</kbd>) in 
    757      * table or column names. 
     758     * (WARNING: using names that require this is a REALLY BAD IDEA) 
     759     * 
     760     * WARNING:  Older versions of MySQL can't handle the backtick 
     761     * character (<kbd>`</kbd>) in table or column names. 
    758762     * 
    759763     * @param string $str  identifier name to be quoted 
     
    766770    function quoteIdentifier($str) 
    767771    { 
    768         return '`' . $str . '`'; 
     772        return '`' . str_replace('`', '``', $str) . '`'; 
    769773    } 
    770774 
     
    853857    function modifyLimitQuery($query, $from, $count, $params = array()) 
    854858    { 
    855         if (DB::isManip($query)) { 
     859        if (DB::isManip($query) || $this->_next_query_manip) { 
    856860            return $query . " LIMIT $count"; 
    857861        } else { 
     
    929933    { 
    930934        if (is_string($result)) { 
     935            // Fix for bug #11580. 
     936            if ($this->_db) { 
     937                if (!@mysql_select_db($this->_db, $this->connection)) { 
     938                    return $this->mysqlRaiseError(DB_ERROR_NODBSELECTED); 
     939                } 
     940            } 
     941             
    931942            /* 
    932943             * Probably received a table name. 
    933944             * Create a result resource identifier. 
    934945             */ 
    935             $id = @mysql_list_fields($this->dsn['database'], 
    936                                      $result, $this->connection); 
     946            $id = @mysql_query("SELECT * FROM $result LIMIT 0", 
     947                               $this->connection); 
    937948            $got_string = true; 
    938949        } elseif (isset($result->result)) { 
  • trunk/roundcubemail/program/lib/DB/mysqli.php

    r12 r1377  
    1818 * @package    DB 
    1919 * @author     Daniel Convissor <danielc@php.net> 
    20  * @copyright  1997-2005 The PHP Group 
     20 * @copyright  1997-2007 The PHP Group 
    2121 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2222 * @version    CVS: $Id$ 
     
    4242 * @package    DB 
    4343 * @author     Daniel Convissor <danielc@php.net> 
    44  * @copyright  1997-2005 The PHP Group 
     44 * @copyright  1997-2007 The PHP Group 
    4545 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    46  * @version    Release: @package_version@ 
     46 * @version    Release: 1.7.13 
    4747 * @link       http://pear.php.net/package/DB 
    4848 * @since      Class functional since Release 1.6.3 
     
    115115        1216 => DB_ERROR_CONSTRAINT, 
    116116        1217 => DB_ERROR_CONSTRAINT, 
     117        1356 => DB_ERROR_DIVZERO, 
     118        1451 => DB_ERROR_CONSTRAINT, 
     119        1452 => DB_ERROR_CONSTRAINT, 
    117120    ); 
    118121 
     
    211214        MYSQLI_TYPE_STRING      => 'char', 
    212215        MYSQLI_TYPE_GEOMETRY    => 'geometry', 
     216        /* These constants are conditionally compiled in ext/mysqli, so we'll 
     217         * define them by number rather than constant. */ 
     218        16                      => 'bit', 
     219        246                     => 'decimal', 
    213220    ); 
    214221 
     
    265272     * ); 
    266273     *  
    267      * $db =& DB::connect($dsn, $options); 
     274     * $db = DB::connect($dsn, $options); 
    268275     * if (PEAR::isError($db)) { 
    269276     *     die($db->getMessage()); 
     
    288295 
    289296        $ini = ini_get('track_errors'); 
    290         ini_set('track_errors', 1); 
     297        @ini_set('track_errors', 1); 
    291298        $php_errormsg = ''; 
    292299 
    293         if ($this->getOption('ssl') === true) { 
     300        if (((int) $this->getOption('ssl')) === 1) { 
    294301            $init = mysqli_init(); 
    295302            mysqli_ssl_set( 
     
    323330        } 
    324331 
    325         ini_set('track_errors', $ini); 
     332        @ini_set('track_errors', $ini); 
    326333 
    327334        if (!$this->connection) { 
     
    373380    function simpleQuery($query) 
    374381    { 
    375         $ismanip = DB::isManip($query); 
     382        $ismanip = $this->_checkManip($query); 
    376383        $this->last_query = $query; 
    377384        $query = $this->modifyQuery($query); 
     
    491498    function freeResult($result) 
    492499    { 
    493         return @mysqli_free_result($result); 
     500        return is_resource($result) ? mysqli_free_result($result) : false; 
    494501    } 
    495502 
     
    627634    function affectedRows() 
    628635    { 
    629         if (DB::isManip($this->last_query)) { 
     636        if ($this->_last_query_manip) { 
    630637            return @mysqli_affected_rows($this->connection); 
    631638        } else { 
     
    824831    /** 
    825832     * Quotes a string so it can be safely used as a table or column name 
    826      * 
    827      * MySQL can't handle the backtick character (<kbd>`</kbd>) in 
    828      * table or column names. 
     833     * (WARNING: using names that require this is a REALLY BAD IDEA) 
     834     * 
     835     * WARNING:  Older versions of MySQL can't handle the backtick 
     836     * character (<kbd>`</kbd>) in table or column names. 
    829837     * 
    830838     * @param string $str  identifier name to be quoted 
     
    837845    function quoteIdentifier($str) 
    838846    { 
    839         return '`' . $str . '`'; 
     847        return '`' . str_replace('`', '``', $str) . '`'; 
    840848    } 
    841849 
     
    879887    function modifyLimitQuery($query, $from, $count, $params = array()) 
    880888    { 
    881         if (DB::isManip($query)) { 
     889        if (DB::isManip($query) || $this->_next_query_manip) { 
    882890            return $query . " LIMIT $count"; 
    883891        } else { 
     
    955963    { 
    956964        if (is_string($result)) { 
     965            // Fix for bug #11580. 
     966            if ($this->_db) { 
     967                if (!@mysqli_select_db($this->connection, $this->_db)) { 
     968                    return $this->mysqliRaiseError(DB_ERROR_NODBSELECTED); 
     969                } 
     970            } 
     971 
    957972            /* 
    958973             * Probably received a table name. 
     
    10161031                                    ? $this->mysqli_types[$tmp->type] 
    10171032                                    : 'unknown', 
    1018                 'len'   => $tmp->max_length, 
     1033                // http://bugs.php.net/?id=36579 
     1034                'len'   => $tmp->length, 
    10191035                'flags' => $flags, 
    10201036            ); 
  • trunk/roundcubemail/program/lib/DB/oci8.php

    r12 r1377  
    1919 * @author     James L. Pine <jlp@valinux.com> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    4646 * @author     James L. Pine <jlp@valinux.com> 
    4747 * @author     Daniel Convissor <danielc@php.net> 
    48  * @copyright  1997-2005 The PHP Group 
     48 * @copyright  1997-2007 The PHP Group 
    4949 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    50  * @version    Release: @package_version@ 
     50 * @version    Release: 1.7.13 
    5151 * @link       http://pear.php.net/package/DB 
    5252 */ 
     
    9595     */ 
    9696    var $errorcode_map = array( 
    97         1    => DB_ERROR_CONSTRAINT, 
    98         900  => DB_ERROR_SYNTAX, 
    99         904  => DB_ERROR_NOSUCHFIELD, 
    100         913  => DB_ERROR_VALUE_COUNT_ON_ROW, 
    101         921  => DB_ERROR_SYNTAX, 
    102         923  => DB_ERROR_SYNTAX, 
    103         942  => DB_ERROR_NOSUCHTABLE, 
    104         955  => DB_ERROR_ALREADY_EXISTS, 
    105         1400 => DB_ERROR_CONSTRAINT_NOT_NULL, 
    106         1401 => DB_ERROR_INVALID, 
    107         1407 => DB_ERROR_CONSTRAINT_NOT_NULL, 
    108         1418 => DB_ERROR_NOT_FOUND, 
    109         1476 => DB_ERROR_DIVZERO, 
    110         1722 => DB_ERROR_INVALID_NUMBER, 
    111         2289 => DB_ERROR_NOSUCHTABLE, 
    112         2291 => DB_ERROR_CONSTRAINT, 
    113         2292 => DB_ERROR_CONSTRAINT, 
    114         2449 => DB_ERROR_CONSTRAINT, 
     97        1     => DB_ERROR_CONSTRAINT, 
     98        900   => DB_ERROR_SYNTAX, 
     99        904   => DB_ERROR_NOSUCHFIELD, 
     100        913   => DB_ERROR_VALUE_COUNT_ON_ROW, 
     101        921   => DB_ERROR_SYNTAX, 
     102        923   => DB_ERROR_SYNTAX, 
     103        942   => DB_ERROR_NOSUCHTABLE, 
     104        955   => DB_ERROR_ALREADY_EXISTS, 
     105        1400  => DB_ERROR_CONSTRAINT_NOT_NULL, 
     106        1401  => DB_ERROR_INVALID, 
     107        1407  => DB_ERROR_CONSTRAINT_NOT_NULL, 
     108        1418  => DB_ERROR_NOT_FOUND, 
     109        1476  => DB_ERROR_DIVZERO, 
     110        1722  => DB_ERROR_INVALID_NUMBER, 
     111        2289  => DB_ERROR_NOSUCHTABLE, 
     112        2291  => DB_ERROR_CONSTRAINT, 
     113        2292  => DB_ERROR_CONSTRAINT, 
     114        2449  => DB_ERROR_CONSTRAINT, 
     115        12899 => DB_ERROR_INVALID, 
    115116    ); 
    116117 
     
    160161     */ 
    161162    var $manip_query = array(); 
     163 
     164    /** 
     165     * Store of prepared SQL queries. 
     166     * @var array 
     167     * @access private 
     168     */ 
     169    var $_prepared_queries = array(); 
    162170 
    163171 
     
    217225        } 
    218226 
     227        // Backwards compatibility with DB < 1.7.0 
     228        if (empty($dsn['database']) && !empty($dsn['hostspec'])) { 
     229            $db = $dsn['hostspec']; 
     230        } else { 
     231            $db = $dsn['database']; 
     232        } 
     233 
    219234        if (function_exists('oci_connect')) { 
    220235            if (isset($dsn['new_link']) 
     
    226241                                    : 'oci_connect'; 
    227242            } 
    228  
    229             // Backwards compatibility with DB < 1.7.0 
    230             if (empty($dsn['database']) && !empty($dsn['hostspec'])) { 
    231                 $db = $dsn['hostspec']; 
    232             } else { 
    233                 $db = $dsn['database']; 
     243            if (isset($this->dsn['port']) && $this->dsn['port']) { 
     244                $db = '//'.$db.':'.$this->dsn['port']; 
    234245            } 
    235246 
     
    249260        } else { 
    250261            $connect_function = $persistent ? 'OCIPLogon' : 'OCILogon'; 
    251             if ($dsn['hostspec']) { 
     262            if ($db) { 
    252263                $this->connection = @$connect_function($dsn['username'], 
    253264                                                       $dsn['password'], 
    254                                                        $dsn['hostspec']); 
     265                                                       $db); 
    255266            } elseif ($dsn['username'] || $dsn['password']) { 
    256267                $this->connection = @$connect_function($dsn['username'], 
     
    323334        } 
    324335        $this->last_stmt = $result; 
    325         if (DB::isManip($query)) { 
     336        if ($this->_checkManip($query)) { 
    326337            return DB_OK; 
    327338        } else { 
     
    416427    function freeResult($result) 
    417428    { 
    418         return @OCIFreeStatement($result); 
     429        return is_resource($result) ? OCIFreeStatement($result) : false; 
    419430    } 
    420431 
     
    477488            $save_stmt = $this->last_stmt; 
    478489 
    479             if (count($this->_data)) { 
    480                 $smt = $this->prepare('SELECT COUNT(*) FROM ('.$this->last_query.')'); 
    481                 $count = $this->execute($smt, $this->_data); 
    482             } else { 
    483                 $count =& $this->query($countquery); 
    484             } 
    485  
     490            $count = $this->query($countquery); 
     491 
     492            // Restore the last query and statement. 
     493            $this->last_query = $save_query; 
     494            $this->last_stmt = $save_stmt; 
     495             
    486496            if (DB::isError($count) || 
    487497                DB::isError($row = $count->fetchRow(DB_FETCHMODE_ORDERED))) 
    488498            { 
    489                 $this->last_query = $save_query; 
    490                 $this->last_stmt = $save_stmt; 
    491499                return $this->raiseError(DB_ERROR_NOT_CAPABLE); 
    492500            } 
     501 
    493502            return $row[0]; 
    494503        } 
     
    591600        $this->prepare_types[(int)$stmt] = $types; 
    592601        $this->manip_query[(int)$stmt] = DB::isManip($query); 
     602        $this->_prepared_queries[(int)$stmt] = $newquery; 
    593603        return $stmt; 
    594604    } 
     
    621631        $data = (array)$data; 
    622632        $this->last_parameters = $data; 
     633        $this->last_query = $this->_prepared_queries[(int)$stmt]; 
    623634        $this->_data = $data; 
    624635 
    625         $types =& $this->prepare_types[(int)$stmt]; 
     636        $types = $this->prepare_types[(int)$stmt]; 
    626637        if (count($types) != count($data)) { 
    627             $tmp =& $this->raiseError(DB_ERROR_MISMATCH); 
     638            $tmp = $this->raiseError(DB_ERROR_MISMATCH); 
    628639            return $tmp; 
    629640        } 
     
    644655                $fp = @fopen($data[$key], 'rb'); 
    645656                if (!$fp) { 
    646                     $tmp =& $this->raiseError(DB_ERROR_ACCESS_VIOLATION); 
     657                    $tmp = $this->raiseError(DB_ERROR_ACCESS_VIOLATION); 
    647658                    return $tmp; 
    648659                } 
    649660                $data[$key] = fread($fp, filesize($data[$key])); 
    650661                fclose($fp); 
     662            } elseif ($types[$i] == DB_PARAM_SCALAR) { 
     663                // Floats have to be converted to a locale-neutral 
     664                // representation. 
     665                if (is_float($data[$key])) { 
     666                    $data[$key] = $this->quoteFloat($data[$key]); 
     667                } 
    651668            } 
    652669            if (!@OCIBindByName($stmt, ':bind' . $i, $data[$key], -1)) { 
     
    654671                return $tmp; 
    655672            } 
     673            $this->last_query = str_replace(':bind'.$i, $this->quoteSmart($data[$key]), $this->last_query); 
    656674            $i++; 
    657675        } 
     
    666684        } 
    667685        $this->last_stmt = $stmt; 
    668         if ($this->manip_query[(int)$stmt]) { 
     686        if ($this->manip_query[(int)$stmt] || $this->_next_query_manip) { 
     687            $this->_last_query_manip = true; 
     688            $this->_next_query_manip = false; 
    669689            $tmp = DB_OK; 
    670690        } else { 
     691            $this->_last_query_manip = false; 
    671692            @ocisetprefetch($stmt, $this->options['result_buffering']); 
    672             $tmp =& new DB_result($this, $stmt); 
     693            $tmp = new DB_result($this, $stmt); 
    673694        } 
    674695        return $tmp; 
     
    798819            $result = $this->prepare("SELECT * FROM ($query) " 
    799820                                     . 'WHERE NULL = NULL'); 
    800             $tmp =& $this->execute($result, $params); 
     821            $tmp = $this->execute($result, $params); 
    801822        } else { 
    802823            $q_fields = "SELECT * FROM ($query) WHERE NULL = NULL"; 
     
    858879        do { 
    859880            $this->expectError(DB_ERROR_NOSUCHTABLE); 
    860             $result =& $this->query("SELECT ${seqname}.nextval FROM dual"); 
     881            $result = $this->query("SELECT ${seqname}.nextval FROM dual"); 
    861882            $this->popExpect(); 
    862883            if ($ondemand && DB::isError($result) && 
     
    10161037                return $this->oci8RaiseError($stmt); 
    10171038            } 
    1018  
     1039             
    10191040            $i = 0; 
    10201041            while (@OCIFetch($stmt)) { 
     
    10991120            case 'synonyms': 
    11001121                return 'SELECT synonym_name FROM user_synonyms'; 
     1122            case 'views': 
     1123                return 'SELECT view_name FROM user_views'; 
    11011124            default: 
    11021125                return null; 
     
    11041127    } 
    11051128 
     1129    // }}} 
     1130    // {{{ quoteFloat() 
     1131 
     1132    /** 
     1133     * Formats a float value for use within a query in a locale-independent 
     1134     * manner. 
     1135     * 
     1136     * @param float the float value to be quoted. 
     1137     * @return string the quoted string. 
     1138     * @see DB_common::quoteSmart() 
     1139     * @since Method available since release 1.7.8. 
     1140     */ 
     1141    function quoteFloat($float) { 
     1142        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); 
     1143    } 
     1144      
    11061145    // }}} 
    11071146 
  • trunk/roundcubemail/program/lib/DB/odbc.php

    r12 r1377  
    1919 * @author     Stig Bakken <ssb@php.net> 
    2020 * @author     Daniel Convissor <danielc@php.net> 
    21  * @copyright  1997-2005 The PHP Group 
     21 * @copyright  1997-2007 The PHP Group 
    2222 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2323 * @version    CVS: $Id$ 
     
    4343 * @author     Stig Bakken <ssb@php.net> 
    4444 * @author     Daniel Convissor <danielc@php.net> 
    45  * @copyright  1997-2005 The PHP Group 
     45 * @copyright  1997-2007 The PHP Group 
    4646 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    47  * @version    Release: @package_version@ 
     47 * @version    Release: 1.7.13 
    4848 * @link       http://pear.php.net/package/DB 
    4949 */ 
     
    267267        // Determine which queries that should return data, and which 
    268268        // should return an error code only. 
    269         if (DB::isManip($query)) { 
     269        if ($this->_checkManip($query)) { 
    270270            $this->affected = $result; // For affectedRows() 
    271271            return DB_OK; 
     
    368368    function freeResult($result) 
    369369    { 
    370         return @odbc_free_result($result); 
     370        return is_resource($result) ? odbc_free_result($result) : false; 
    371371    } 
    372372 
  • trunk/roundcubemail/program/lib/DB/pgsql.php

    r12 r1377  
    2020 * @author     Stig Bakken <ssb@php.net> 
    2121 * @author     Daniel Convissor <danielc@php.net> 
    22  * @copyright  1997-2005 The PHP Group 
     22 * @copyright  1997-2007 The PHP Group 
    2323 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2424 * @version    CVS: $Id$ 
     
    4242 * @author     Stig Bakken <ssb@php.net> 
    4343 * @author     Daniel Convissor <danielc@php.net> 
    44  * @copyright  1997-2005 The PHP Group 
     44 * @copyright  1997-2007 The PHP Group 
    4545 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    46  * @version    Release: @package_version@ 
     46 * @version    Release: 1.7.13 
    4747 * @link       http://pear.php.net/package/DB 
    4848 */ 
     
    194194     * ); 
    195195     *  
    196      * $db =& DB::connect($dsn, $options); 
     196     * $db = DB::connect($dsn, $options); 
    197197     * if (PEAR::isError($db)) { 
    198198     *     die($db->getMessage()); 
     
    278278                                                      $params); 
    279279        } else { 
    280             ini_set('track_errors', 1); 
     280            @ini_set('track_errors', 1); 
    281281            $this->connection = @call_user_func_array($connect_function, 
    282282                                                      $params); 
    283             ini_set('track_errors', $ini); 
     283            @ini_set('track_errors', $ini); 
    284284        } 
    285285 
     
    321321    function simpleQuery($query) 
    322322    { 
    323         $ismanip = DB::isManip($query); 
     323        $ismanip = $this->_checkManip($query); 
    324324        $this->last_query = $query; 
    325325        $query = $this->modifyQuery($query); 
     
    337337            return $this->pgsqlRaiseError(); 
    338338        } 
    339         // Determine which queries that should return data, and which 
    340         // should return an error code only. 
     339 
     340        /* 
     341         * Determine whether queries produce affected rows, result or nothing. 
     342         * 
     343         * This logic was introduced in version 1.1 of the file by ssb, 
     344         * though the regex has been modified slightly since then. 
     345         * 
     346         * PostgreSQL commands: 
     347         * ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY, 
     348         * CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH, 
     349         * GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET, 
     350         * REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW, 
     351         * UNLISTEN, UPDATE, VACUUM 
     352         */ 
    341353        if ($ismanip) { 
    342354            $this->affected = @pg_affected_rows($result); 
    343355            return DB_OK; 
    344         } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|SHOW)\s/si', $query)) { 
    345             /* PostgreSQL commands: 
    346                ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY, 
    347                CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH, 
    348                GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET, 
    349                REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW, 
    350                UNLISTEN, UPDATE, VACUUM 
    351             */ 
     356        } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW)\s/si', 
     357                             $query)) 
     358        { 
    352359            $this->row[(int)$result] = 0; // reset the row counter. 
    353360            $numrows = $this->numRows($result); 
     
    472479 
    473480    // }}} 
    474     // {{{ quoteSmart() 
    475  
    476     /** 
    477      * Formats input so it can be safely used in a query 
    478      * 
    479      * @param mixed $in  the data to be formatted 
    480      * 
    481      * @return mixed  the formatted data.  The format depends on the input's 
    482      *                 PHP type: 
    483      *                 + null = the string <samp>NULL</samp> 
    484      *                 + boolean = string <samp>TRUE</samp> or <samp>FALSE</samp> 
    485      *                 + integer or double = the unquoted number 
    486      *                 + other (including strings and numeric strings) = 
    487      *                   the data escaped according to MySQL's settings 
    488      *                   then encapsulated between single quotes 
     481    // {{{ quoteBoolean() 
     482 
     483    /** 
     484     * Formats a boolean value for use within a query in a locale-independent 
     485     * manner. 
     486     * 
     487     * @param boolean the boolean value to be quoted. 
     488     * @return string the quoted string. 
     489     * @see DB_common::quoteSmart() 
     490     * @since Method available since release 1.7.8. 
     491     */ 
     492    function quoteBoolean($boolean) { 
     493        return $boolean ? 'TRUE' : 'FALSE'; 
     494    } 
     495      
     496    // }}} 
     497    // {{{ escapeSimple() 
     498 
     499    /** 
     500     * Escapes a string according to the current DBMS's standards 
     501     * 
     502     * {@internal PostgreSQL treats a backslash as an escape character, 
     503     * so they are escaped as well. 
     504     * 
     505     * @param string $str  the string to be escaped 
     506     * 
     507     * @return string  the escaped string 
    489508     * 
    490509     * @see DB_common::quoteSmart() 
    491510     * @since Method available since Release 1.6.0 
    492511     */ 
    493     function quoteSmart($in) 
    494     { 
    495         if (is_int($in) || is_double($in)) { 
    496             return $in; 
    497         } elseif (is_bool($in)) { 
    498             return $in ? 'TRUE' : 'FALSE'; 
    499         } elseif (is_null($in)) { 
    500             return 'NULL'; 
     512    function escapeSimple($str) 
     513    { 
     514        if (function_exists('pg_escape_string')) { 
     515            /* This fixes an undocumented BC break in PHP 5.2.0 which changed 
     516             * the prototype of pg_escape_string. I'm not thrilled about having 
     517             * to sniff the PHP version, quite frankly, but it's the only way 
     518             * to deal with the problem. Revision 1.331.2.13.2.10 on 
     519             * php-src/ext/pgsql/pgsql.c (PHP_5_2 branch) is to blame, for the 
     520             * record. */ 
     521            if (version_compare(PHP_VERSION, '5.2.0', '>=')) { 
     522                return pg_escape_string($this->connection, $str); 
     523            } else { 
     524                return pg_escape_string($str); 
     525            } 
    501526        } else { 
    502             return "'" . $this->escapeSimple($in) . "'"; 
    503         } 
    504     } 
    505  
    506     // }}} 
    507     // {{{ escapeSimple() 
    508  
    509     /** 
    510      * Escapes a string according to the current DBMS's standards 
    511      * 
    512      * {@internal PostgreSQL treats a backslash as an escape character, 
    513      * so they are escaped as well. 
    514      * 
    515      * Not using pg_escape_string() yet because it requires PostgreSQL 
    516      * to be at version 7.2 or greater.}} 
    517      * 
    518      * @param string $str  the string to be escaped 
    519      * 
    520      * @return string  the escaped string 
    521      * 
    522      * @see DB_common::quoteSmart() 
    523      * @since Method available since Release 1.6.0 
    524      */ 
    525     function escapeSimple($str) 
    526     { 
    527         return str_replace("'", "''", str_replace('\\', '\\\\', $str)); 
     527            return str_replace("'", "''", str_replace('\\', '\\\\', $str)); 
     528        } 
    528529    } 
    529530 
     
    676677        do { 
    677678            $this->pushErrorHandling(PEAR_ERROR_RETURN); 
    678             $result =& $this->query("SELECT NEXTVAL('${seqname}')"); 
     679            $result = $this->query("SELECT NEXTVAL('${seqname}')"); 
    679680            $this->popErrorHandling(); 
    680681            if ($ondemand && DB::isError($result) && 
     
    780781    { 
    781782        $native = $this->errorNative(); 
     783        if (!$native) { 
     784            $native = 'Database connection has been lost.'; 
     785            $errno = DB_ERROR_CONNECT_FAILED; 
     786        } 
    782787        if ($errno === null) { 
    783788            $errno = $this->errorCode($native); 
     
    816821        if (!isset($error_regexps)) { 
    817822            $error_regexps = array( 
     823                '/column .* (of relation .*)?does not exist/i' 
     824                    => DB_ERROR_NOSUCHFIELD, 
    818825                '/(relation|sequence|table).*does not exist|class .* not found/i' 
    819826                    => DB_ERROR_NOSUCHTABLE, 
    820827                '/index .* does not exist/' 
    821828                    => DB_ERROR_NOT_FOUND, 
    822                 '/column .* does not exist/i' 
    823                     => DB_ERROR_NOSUCHFIELD, 
    824829                '/relation .* already exists/i' 
    825830                    => DB_ERROR_ALREADY_EXISTS, 
     
    977982        $field_name = @pg_fieldname($resource, $num_field); 
    978983 
     984        // Check if there's a schema in $table_name and update things 
     985        // accordingly. 
     986        $from = 'pg_attribute f, pg_class tab, pg_type typ'; 
     987        if (strpos($table_name, '.') !== false) { 
     988            $from .= ', pg_namespace nsp'; 
     989            list($schema, $table) = explode('.', $table_name); 
     990            $tableWhere = "tab.relname = '$table' AND tab.relnamespace = nsp.oid AND nsp.nspname = '$schema'"; 
     991        } else { 
     992            $tableWhere = "tab.relname = '$table_name'"; 
     993        } 
     994 
    979995        $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef 
    980                                 FROM pg_attribute f, pg_class tab, pg_type typ 
     996                                FROM $from 
    981997                                WHERE tab.relname = typ.typname 
    982998                                AND typ.typrelid = f.attrelid 
    983999                                AND f.attname = '$field_name' 
    984                                 AND tab.relname = '$table_name'"); 
     1000                                AND $tableWhere"); 
    9851001        if (@pg_numrows($result) > 0) { 
    9861002            $row = @pg_fetch_row($result, 0); 
     
    9891005            if ($row[1] == 't') { 
    9901006                $result = @pg_exec($this->connection, "SELECT a.adsrc 
    991                                     FROM pg_attribute f, pg_class tab, pg_type typ, pg_attrdef a 
     1007                                    FROM $from, pg_attrdef a 
    9921008                                    WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid 
    9931009                                    AND f.attrelid = a.adrelid AND f.attname = '$field_name' 
    994                                     AND tab.relname = '$table_name' AND f.attnum = a.adnum"); 
     1010                                    AND $tableWhere AND f.attnum = a.adnum"); 
    9951011                $row = @pg_fetch_row($result, 0); 
    9961012                $num = preg_replace("/'(.*)'::\w+/", "\\1", $row[0]); 
     
    10011017        } 
    10021018        $result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey 
    1003                                 FROM pg_attribute f, pg_class tab, pg_type typ, pg_index i 
     1019                                FROM $from, pg_index i 
    10041020                                WHERE tab.relname = typ.typname 
    10051021                                AND typ.typrelid = f.attrelid 
    10061022                                AND f.attrelid = i.indrelid 
    10071023                                AND f.attname = '$field_name' 
    1008                                 AND tab.relname = '$table_name'"); 
     1024                                AND $tableWhere"); 
    10091025        $count = @pg_numrows($result); 
    10101026 
     
    10671083                        . ' WHERE schemaname NOT IN' 
    10681084                        . " ('pg_catalog', 'information_schema', 'pg_toast')"; 
     1085            case 'schema.views': 
     1086                return "SELECT schemaname || '.' || viewname from pg_views WHERE schemaname" 
     1087                        . " NOT IN ('information_schema', 'pg_catalog')"; 
    10691088            case 'views': 
    10701089                // Table cols: viewname | viewowner | definition 
  • trunk/roundcubemail/program/lib/DB/sqlite.php

    r12 r1377  
    2020 * @author     Mika Tuupola <tuupola@appelsiini.net> 
    2121 * @author     Daniel Convissor <danielc@php.net> 
    22  * @copyright  1997-2005 The PHP Group 
     22 * @copyright  1997-2007 The PHP Group 
    2323 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 3.0 
    2424 * @version    CVS: $Id$ 
     
    4646 * @author     Mika Tuupola <tuupola@appelsiini.net> 
    4747 * @author     Daniel Convissor <danielc@php.net> 
    48  * @copyright  1997-2005 The PHP Group 
     48 * @copyright  1997-2007 The PHP Group 
    4949 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 3.0 
    50  * @version    Release: @package_version@ 
     50 * @version    Release: 1.7.13 
    5151 * @link       http://pear.php.net/package/DB 
    5252 */ 
     
    183183     * ); 
    184184     *  
    185      * $db =& DB::connect($dsn, $options); 
     185     * $db = DB::connect($dsn, $options); 
    186186     * if (PEAR::isError($db)) { 
    187187     *     die($db->getMessage()); 
     
    205205        } 
    206206 
    207         if ($dsn['database']) { 
     207        if (!$dsn['database']) { 
     208            return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); 
     209        } 
     210 
     211        if ($dsn['database'] !== ':memory:') { 
    208212            if (!file_exists($dsn['database'])) { 
    209213                if (!touch($dsn['database'])) { 
     
    230234                return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); 
    231235            } 
    232         } else { 
    233             return $this->sqliteRaiseError(DB_ERROR_ACCESS_VIOLATION); 
    234236        } 
    235237 
     
    237239 
    238240        // track_errors must remain on for simpleQuery() 
    239         ini_set('track_errors', 1); 
     241        @ini_set('track_errors', 1); 
    240242        $php_errormsg = ''; 
    241243 
     
    281283    function simpleQuery($query) 
    282284    { 
    283         $ismanip = DB::isManip($query); 
     285        $ismanip = $this->_checkManip($query); 
    284286        $this->last_query = $query; 
    285287        $query = $this->modifyQuery($query); 
     
    357359            if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { 
    358360                $arr = array_change_key_case($arr, CASE_LOWER); 
     361            } 
     362 
     363            /* Remove extraneous " characters from the fields in the result. 
     364             * Fixes bug #11716. */ 
     365            if (is_array($arr) && count($arr) > 0) { 
     366                $strippedArr = array(); 
     367                foreach ($arr as $field => $value) { 
     368                    $strippedArr[trim($field, '"')] = $value; 
     369                } 
     370                $arr = $strippedArr; 
    359371            } 
    360372        } else { 
     
    728740    { 
    729741        static $error_regexps; 
     742         
     743        // PHP 5.2+ prepends the function name to $php_errormsg, so we need 
     744        // this hack to work around it, per bug #9599. 
     745        $errormsg = preg_replace('/^sqlite[a-z_]+\(\): /', '', $errormsg); 
     746         
    730747        if (!isset($error_regexps)) { 
    731748            $error_regexps = array( 
  • trunk/roundcubemail/program/lib/DB/storage.php

    r12 r1377  
    1717 * @package    DB 
    1818 * @author     Stig Bakken <stig@php.net> 
    19  * @copyright  1997-2005 The PHP Group 
     19 * @copyright  1997-2007 The PHP Group 
    2020 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2121 * @version    CVS: $Id$ 
     
    3737 * @package    DB 
    3838 * @author     Stig Bakken <stig@php.net> 
    39  * @copyright  1997-2005 The PHP Group 
     39 * @copyright  1997-2007 The PHP Group 
    4040 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    41  * @version    Release: @package_version@ 
     41 * @version    Release: 1.7.13 
    4242 * @link       http://pear.php.net/package/DB 
    4343 */ 
     
    294294    { 
    295295        $classname = strtolower(get_class($this)); 
    296         $obj =& new $classname($table); 
     296        $obj = new $classname($table); 
    297297        foreach ($data as $name => $value) { 
    298298            $obj->_properties[$name] = true; 
     
    446446    function store() 
    447447    { 
     448        $params = array(); 
     449        $vars = array(); 
    448450        foreach ($this->_changes as $name => $foo) { 
    449451            $params[] = &$this->$name; 
  • trunk/roundcubemail/program/lib/DB/sybase.php

    r12 r1377  
    2020 * @author     Antônio Carlos Venâncio Júnior <floripa@php.net> 
    2121 * @author     Daniel Convissor <danielc@php.net> 
    22  * @copyright  1997-2005 The PHP Group 
     22 * @copyright  1997-2007 The PHP Group 
    2323 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    2424 * @version    CVS: $Id$ 
     
    4545 * @author     Antônio Carlos Venâncio Júnior <floripa@php.net> 
    4646 * @author     Daniel Convissor <danielc@php.net> 
    47  * @copyright  1997-2005 The PHP Group 
     47 * @copyright  1997-2007 The PHP Group 
    4848 * @license    http://www.php.net/license/3_0.txt  PHP License 3.0 
    49  * @version    Release: @package_version@ 
     49 * @version    Release: 1.7.13 
    5050 * @link       http://pear.php.net/package/DB 
    5151 */ 
     
    249249    function simpleQuery($query) 
    250250    { 
    251         $ismanip = DB::isManip($query); 
     251        $ismanip = $this->_checkManip($query); 
    252252        $this->last_query = $query; 
    253         if (!@sybase_select_db($this->_db, $this->connection)) { 
     253        if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { 
    254254            return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); 
    255255        } 
     
    371371    function freeResult($result) 
    372372    { 
    373         return @sybase_free_result($result); 
     373        return is_resource($result) ? sybase_free_result($result) : false; 
    374374    } 
    375375 
     
    436436    function affectedRows() 
    437437    { 
    438         if (DB::isManip($this->last_query)) { 
     438        if ($this->_last_query_manip) { 
    439439            $result = @sybase_affected_rows($this->connection); 
    440440        } else { 
     
    463463    { 
    464464        $seqname = $this->getSequenceName($seq_name); 
    465         if (!@sybase_select_db($this->_db, $this->connection)) { 
     465        if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { 
    466466            return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); 
    467467        } 
     
    480480                } 
    481481            } elseif (!DB::isError($result)) { 
    482                 $result =& $this->query("SELECT @@IDENTITY FROM $seqname"); 
     482                $result = $this->query("SELECT @@IDENTITY FROM $seqname"); 
    483483                $repeat = 0; 
    484484            } else { 
     
    530530 
    531531    // }}} 
     532    // {{{ quoteFloat() 
     533 
     534    /** 
     535     * Formats a float value for use within a query in a locale-independent 
     536     * manner. 
     537     * 
     538     * @param float the float value to be quoted. 
     539     * @return string the quoted string. 
     540     * @see DB_common::quoteSmart() 
     541     * @since Method available since release 1.7.8. 
     542     */ 
     543    function quoteFloat($float) { 
     544        return $this->escapeSimple(str_replace(',', '.', strval(floatval($float)))); 
     545    } 
     546      
     547    // }}} 
    532548    // {{{ autoCommit() 
    533549 
     
    559575    { 
    560576        if ($this->transaction_opcount > 0) { 
    561             if (!@sybase_select_db($this->_db, $this->connection)) { 
     577            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { 
    562578                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); 
    563579            } 
     
    582598    { 
    583599        if ($this->transaction_opcount > 0) { 
    584             if (!@sybase_select_db($this->_db, $this->connection)) { 
     600            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { 
    585601                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); 
    586602            } 
     
    643659    { 
    644660        static $error_regexps; 
     661         
     662        // PHP 5.2+ prepends the function name to $php_errormsg, so we need 
     663        // this hack to work around it, per bug #9599. 
     664        $errormsg = preg_replace('/^sybase[a-z_]+\(\): /', '', $errormsg); 
     665         
    645666        if (!isset($error_regexps)) { 
    646667            $error_regexps = array( 
     
    675696                '/^There are fewer columns in the INSERT statement than values specified/i' 
    676697                    => DB_ERROR_VALUE_COUNT_ON_ROW, 
     698                '/Divide by zero/i' 
     699                    => DB_ERROR_DIVZERO, 
    677700            ); 
    678701        } 
     
    715738             * Create a result resource identifier. 
    716739             */ 
    717             if (!@sybase_select_db($this->_db, $this->connection)) { 
     740            if ($this->_db && !@sybase_select_db($this->_db, $this->connection)) { 
    718741                return $this->sybaseRaiseError(DB_ERROR_NODBSELECTED); 
    719742            } 
     
    812835            $tableName = $table; 
    813836 
    814             // get unique/primary keys 
    815             $res = $this->getAll("sp_helpindex $table", DB_FETCHMODE_ASSOC); 
    816  
    817             if (!isset($res[0]['index_description'])) { 
     837            /* We're running sp_helpindex directly because it doesn't exist in 
     838             * older versions of ASE -- unfortunately, we can't just use 
     839             * DB::isError() because the user may be using callback error 
     840             * handling. */ 
     841            $res = @sybase_query("sp_helpindex $table", $this->connection); 
     842 
     843            if ($res === false || $res === true) { 
     844                // Fake a valid response for BC reasons. 
    818845                return ''; 
    819846            } 
    820847 
    821             foreach ($res as $val) { 
     848            while (($val = sybase_fetch_assoc($res)) !== false) { 
     849                if (!isset($val['index_keys'])) { 
     850                    /* No useful information returned. Break and be done with 
     851                     * it, which preserves the pre-1.7.9 behaviour. */ 
     852                    break; 
     853                } 
     854 
    822855                $keys = explode(', ', trim($val['index_keys'])); 
    823856 
     
    834867                } 
    835868            } 
     869 
     870            sybase_free_result($res); 
    836871 
    837872        } 
Note: See TracChangeset for help on using the changeset viewer.