From b7ebb28ba3dc9182a13f36ba643f1a3486bfbe39 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 25 Dec 2019 07:43:27 +1100 Subject: [PATCH] Upgrade DB package to be version 1.9.3 --- DB.php | 71 ++++++++++++++++++++++++++++++-------------------- DB/common.php | 52 ++++++++++++++++++++++-------------- DB/dbase.php | 10 +++---- DB/mssql.php | 29 ++++++++++++++++++--- DB/mysql.php | 31 ++++++++++------------ DB/mysqli.php | 28 +++++++++++++------- DB/odbc.php | 20 +++----------- DB/pgsql.php | 67 ++++++++++++++++++++++++++--------------------- DB/storage.php | 8 +++--- 9 files changed, 183 insertions(+), 133 deletions(-) diff --git a/DB.php b/DB.php index 90f9d6362..f048bc378 100644 --- a/DB.php +++ b/DB.php @@ -5,7 +5,7 @@ /** * Database independent query interface * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -20,7 +20,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: DB.php,v 1.88 2007/08/12 05:27:25 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -49,9 +49,7 @@ /** * Unkown error */ -if (!defined('DB_ERROR')) { - define('DB_ERROR', -1); -} +define('DB_ERROR', -1); /** * Syntax error @@ -442,12 +440,12 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB { - // {{{ &factory() + // {{{ factory() /** * Create a new DB object for the specified database type but don't @@ -460,7 +458,7 @@ class DB * * @see DB_common::setOption() */ - function &factory($type, $options = false) + public static function factory($type, $options = false) { if (!is_array($options)) { $options = array('persistent' => $options); @@ -496,7 +494,7 @@ function &factory($type, $options = false) } // }}} - // {{{ &connect() + // {{{ connect() /** * Create a new DB object including a connection to the specified database @@ -531,7 +529,7 @@ function &factory($type, $options = false) * * @uses DB::parseDSN(), DB_common::setOption(), PEAR::isError() */ - static function &connect($dsn, $options = array()) + public static function connect($dsn, $options = array()) { $dsninfo = DB::parseDSN($dsn); $type = $dsninfo['phptype']; @@ -548,15 +546,15 @@ static function &connect($dsn, $options = array()) // expose php errors with sufficient debug level include_once "DB/${type}.php"; } else { - include_once "DB/${type}.php"; + @include_once "DB/${type}.php"; } $classname = "DB_${type}"; if (!class_exists($classname)) { - $obj = new PEAR; - $tmp = $obj->raiseError(null, DB_ERROR_NOT_FOUND, null, null, + $tmp = PEAR::raiseError(null, DB_ERROR_NOT_FOUND, null, null, "Unable to include the DB/{$type}.php" - . " file for '$dsn'", + . " file for '" + . DB::getDSNString($dsn, true) . "'", 'DB_Error', true); return $tmp; } @@ -593,7 +591,7 @@ static function &connect($dsn, $options = array()) */ function apiVersion() { - return '1.7.13'; + return '1.9.3'; } // }}} @@ -606,9 +604,9 @@ function apiVersion() * * @return bool whether $value is DB_Error object */ - static function isError($value) + public static function isError($value) { - return is_a($value, 'DB_Error'); + return is_object($value) && is_a($value, 'DB_Error'); } // }}} @@ -621,7 +619,7 @@ static function isError($value) * * @return bool whether $value is a DB_ object */ - function isConnection($value) + public static function isConnection($value) { return (is_object($value) && is_subclass_of($value, 'db_common') && @@ -642,15 +640,14 @@ function isConnection($value) * * @return boolean whether $query is a data manipulation query */ - static function isManip($query) + public static function isManip($query) { $manips = 'INSERT|UPDATE|DELETE|REPLACE|' . 'CREATE|DROP|' . 'LOAD DATA|SELECT .* INTO .* FROM|COPY|' . 'ALTER|GRANT|REVOKE|' - . 'SAVEPOINT|ROLLBACK|' . 'LOCK|UNLOCK'; - // First strip any leading comments. + // First strip any leading comments $queryString = (substr($query, 0, 2) === '/*') ? substr($query, strpos($query, '*/') + 2) : $query; if (preg_match('/^\s*"?(' . $manips . ')\s+/i', $queryString)) { return true; @@ -669,7 +666,7 @@ static function isManip($query) * @return string the error message or false if the error code was * not recognized */ - static function errorMessage($value) + public static function errorMessage($value) { static $errorMessages; if (!isset($errorMessages)) { @@ -753,8 +750,9 @@ static function errorMessage($value) * + username: User name for login * + password: Password for login */ - static function parseDSN($dsn) + public static function parseDSN($dsn) { + if (defined('DB_DSN_MODE') && DB_DSN_MODE === 'auto') { if (extension_loaded('mysqli')) { $dsn = preg_replace('/^mysql:/', 'mysqli:', $dsn); @@ -891,7 +889,7 @@ static function parseDSN($dsn) * @param boolean true to hide the password, false to include it * @return string */ - function getDSNString($dsn, $hidePassword) { + public static function getDSNString($dsn, $hidePassword) { /* Calling parseDSN will ensure that we have all the array elements * defined, and means that we deal with strings and array in the same * manner. */ @@ -972,7 +970,7 @@ function getDSNString($dsn, $hidePassword) { * @author Stig Bakken * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_Error extends PEAR_Error @@ -1002,6 +1000,20 @@ function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN, } } + /** + * Workaround to both avoid the "Redefining already defined constructor" + * PHP error and provide backward compatibility in case someone is calling + * DB_Error() dynamically + */ + public function __call($method, $arguments) + { + if ($method == 'DB_Error') { + return call_user_func_array(array($this, '__construct'), $arguments); + } + trigger_error( + 'Call to undefined method DB_Error::' . $method . '()', E_USER_ERROR + ); + } // }}} } @@ -1019,7 +1031,7 @@ function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN, * @author Stig Bakken * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_result @@ -1416,9 +1428,12 @@ function nextResult() function free() { $err = $this->dbh->freeResult($this->result); + if (DB::isError($err)) { + return $err; + } $this->result = false; $this->statement = false; - return $err; + return true; } // }}} @@ -1481,7 +1496,7 @@ function getRowCounter() * @author Stig Bakken * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB * @see DB_common::setFetchMode() */ diff --git a/DB/common.php b/DB/common.php index e7f81588b..1b8197437 100644 --- a/DB/common.php +++ b/DB/common.php @@ -5,7 +5,7 @@ /** * Contains the DB_common base class * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -20,7 +20,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: common.php,v 1.143 2007/09/21 13:40:41 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -42,7 +42,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_common extends PEAR @@ -204,7 +204,7 @@ function __sleep() function __wakeup() { if ($this->was_connected) { - $this->connect($this->dsn, $this->options); + $this->connect($this->dsn, $this->options['persistent']); } } @@ -261,7 +261,7 @@ function toString() */ function quoteString($string) { - $string = $this->quote($string); + $string = $this->quoteSmart($string); if ($string{0} == "'") { return substr($string, 1, -1); } @@ -284,8 +284,7 @@ function quoteString($string) */ function quote($string = null) { - return ($string === null) ? 'NULL' - : "'" . str_replace("'", "''", $string) . "'"; + return $this->quoteSmart($string); } // }}} @@ -1216,7 +1215,8 @@ function modifyLimitQuery($query, $from, $count, $params = array()) */ function &query($query, $params = array()) { - if (sizeof($params) > 0) { + $params = (array)$params; + if (count($params)) { $sth = $this->prepare($query); if (DB::isError($sth)) { return $sth; @@ -1262,7 +1262,7 @@ function &limitQuery($query, $from, $count, $params = array()) return $query; } $result = $this->query($query, $params); - if (is_a($result, 'DB_result')) { + if (is_object($result) && is_a($result, 'DB_result')) { $result->setOption('limit_from', $from); $result->setOption('limit_count', $count); } @@ -1355,8 +1355,8 @@ function &getRow($query, $params = array(), } } // modifyLimitQuery() would be nice here, but it causes BC issues - $params = (array) $params; - if (count($params) > 0) { + $params = (array)$params; + if (count($params)) { $sth = $this->prepare($query); if (DB::isError($sth)) { return $sth; @@ -1664,8 +1664,8 @@ function &getAll($query, $params = array(), } } - $params = (array) $params; - if (count($params) > 0) { + $params = (array)$params; + if (count($params)) { $sth = $this->prepare($query); if (DB::isError($sth)) { @@ -1883,21 +1883,24 @@ function dropSequence($seq_name) * query and native error code. * @param mixed native error code, integer or string depending the * backend + * @param mixed dummy parameter for E_STRICT compatibility with + * PEAR::raiseError + * @param mixed dummy parameter for E_STRICT compatibility with + * PEAR::raiseError * * @return object the PEAR_Error object * * @see PEAR_Error */ function raiseError($code = DB_ERROR, $mode = null, $options = null, - $userinfo = null, $nativecode = null, - $argToMatchParentSignature1 = null, - $argToMatchParentSignature2 = null) + $userinfo = null, $nativecode = null, $dummy1 = null, + $dummy2 = null) { // The error is yet a DB error object if (is_object($code)) { // because we the static PEAR::raiseError, our global // handler should be used if it is set - if ($mode === null && isset($this) && !empty($this->_default_error_mode)) { + if ($mode === null && !empty($this->_default_error_mode)) { $mode = $this->_default_error_mode; $options = $this->_default_error_options; } @@ -1906,7 +1909,7 @@ function raiseError($code = DB_ERROR, $mode = null, $options = null, return $tmp; } - if ($userinfo === null && isset($this)) { + if ($userinfo === null) { $userinfo = $this->last_query; } @@ -2261,10 +2264,21 @@ function _convertNullArrayValuesToEmpty(&$array) } } - function lastInsertId() { + // }}} + // {{{ lastInsertId() + + /** + * Get the most recently inserted Id + * + * @throws RuntimeException + */ + function lastInsertId() + { throw new \RuntimeException("Not implemented: " . get_class($this) . '::lastInsertId'); } + // }}} + } /* diff --git a/DB/dbase.php b/DB/dbase.php index 3a0917455..8324c86b7 100644 --- a/DB/dbase.php +++ b/DB/dbase.php @@ -6,7 +6,7 @@ * The PEAR DB driver for PHP's dbase extension * for interacting with dBase databases * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -20,7 +20,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: dbase.php,v 1.45 2007/09/21 13:40:41 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -41,7 +41,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_dbase extends DB_common @@ -140,7 +140,7 @@ class DB_dbase extends DB_common // {{{ constructor /** - * This constructor calls $this->DB_common() + * This constructor calls parent::__construct() * * @return void */ @@ -402,7 +402,7 @@ function numRows($foo) function quoteBoolean($boolean) { return $boolean ? 'T' : 'F'; } - + // }}} // {{{ tableInfo() diff --git a/DB/mssql.php b/DB/mssql.php index c97ca93eb..31798a5f4 100644 --- a/DB/mssql.php +++ b/DB/mssql.php @@ -6,7 +6,7 @@ * The PEAR DB driver for PHP's mssql extension * for interacting with Microsoft SQL Server databases * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -20,7 +20,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: mssql.php,v 1.92 2007/09/21 13:40:41 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -49,7 +49,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_mssql extends DB_common @@ -179,7 +179,7 @@ class DB_mssql extends DB_common // {{{ constructor /** - * This constructor calls $this->DB_common() + * This constructor calls parent::__construct() * * @return void */ @@ -623,6 +623,27 @@ function dropSequence($seq_name) return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name)); } + // }}} + // {{{ escapeSimple() + + /** + * Escapes a string in a manner suitable for SQL Server. + * + * @param string $str the string to be escaped + * @return string the escaped string + * + * @see DB_common::quoteSmart() + * @since Method available since Release 1.6.0 + */ + function escapeSimple($str) + { + return str_replace( + array("'", "\\\r\n", "\\\n"), + array("''", "\\\\\r\n\r\n", "\\\\\n\n"), + $str + ); + } + // }}} // {{{ quoteIdentifier() diff --git a/DB/mysql.php b/DB/mysql.php index 9ab82dbba..0ff72a485 100644 --- a/DB/mysql.php +++ b/DB/mysql.php @@ -6,7 +6,7 @@ * The PEAR DB driver for PHP's mysql extension * for interacting with MySQL databases * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -20,7 +20,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: mysql.php,v 1.126 2007/09/21 13:32:52 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -41,7 +41,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_mysql extends DB_common @@ -165,7 +165,7 @@ class DB_mysql extends DB_common // {{{ constructor /** - * This constructor calls $this->DB_common() + * This constructor calls parent::__construct() * * @return void */ @@ -775,17 +775,6 @@ function quoteIdentifier($str) return '`' . str_replace('`', '``', $str) . '`'; } - // }}} - // {{{ quote() - - /** - * @deprecated Deprecated in release 1.6.0 - */ - function quote($str = null) - { - return $this->quoteSmart($str); - } - // }}} // {{{ escapeSimple() @@ -801,7 +790,11 @@ function quote($str = null) */ function escapeSimple($str) { - return @mysql_real_escape_string($str, $this->connection); + if (function_exists('mysql_real_escape_string')) { + return @mysql_real_escape_string($str, $this->connection); + } else { + return @mysql_escape_string($str); + } } // }}} @@ -1031,11 +1024,15 @@ function getSpecialQuery($type) } // }}} + // {{{ lastInsertId() - function lastInsertId() { + function lastInsertId() + { return mysql_insert_id($this->connection); } + // }}} + } /* diff --git a/DB/mysqli.php b/DB/mysqli.php index 0b383eeb1..0d8f41421 100644 --- a/DB/mysqli.php +++ b/DB/mysqli.php @@ -6,7 +6,7 @@ * The PEAR DB driver for PHP's mysqli extension * for interacting with MySQL databases * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -19,7 +19,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: mysqli.php,v 1.82 2007/09/21 13:40:41 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -43,7 +43,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB * @since Class functional since Release 1.6.3 */ @@ -227,7 +227,7 @@ class DB_mysqli extends DB_common // {{{ constructor /** - * This constructor calls $this->DB_common() + * This constructor calls parent::__construct() * * @return void */ @@ -256,7 +256,7 @@ function __construct() * Example of how to connect using SSL: * * require_once 'DB.php'; - * + * * $dsn = array( * 'phptype' => 'mysqli', * 'username' => 'someuser', @@ -269,11 +269,11 @@ function __construct() * 'capath' => '/path/to/ca/dir', * 'cipher' => 'AES', * ); - * + * * $options = array( * 'ssl' => true, * ); - * + * * $db = DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db->getMessage()); @@ -500,7 +500,7 @@ function fetchInto($result, &$arr, $fetchmode, $rownum = null) */ function freeResult($result) { - if (!$result instanceof mysqli_result) { + if (! $result instanceof mysqli_result) { return false; } mysqli_free_result($result); @@ -1000,7 +1000,7 @@ function tableInfo($result, $mode = null) $got_string = false; } - if (!is_a($id, 'mysqli_result')) { + if (!is_object($id) || !is_a($id, 'mysqli_result')) { return $this->mysqliRaiseError(DB_ERROR_NEED_MORE_DATA); } @@ -1038,6 +1038,10 @@ function tableInfo($result, $mode = null) ? $this->mysqli_types[$tmp->type] : 'unknown', // http://bugs.php.net/?id=36579 + // Doc Bug #36579: mysqli_fetch_field length handling + // https://bugs.php.net/bug.php?id=62426 + // Bug #62426: mysqli_fetch_field_direct returns incorrect + // length on UTF8 fields 'len' => $tmp->length, 'flags' => $flags, ); @@ -1086,11 +1090,15 @@ function getSpecialQuery($type) } // }}} + // {{{ lastInsertId() - function lastInsertId() { + function lastInsertId() + { return mysqli_insert_id($this->connection); } + // }}} + } /* diff --git a/DB/odbc.php b/DB/odbc.php index 04b3871f1..f410a1271 100644 --- a/DB/odbc.php +++ b/DB/odbc.php @@ -6,7 +6,7 @@ * The PEAR DB driver for PHP's odbc extension * for interacting with databases via ODBC connections * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -20,7 +20,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: odbc.php,v 1.81 2007/07/06 05:19:21 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -44,7 +44,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_odbc extends DB_common @@ -153,7 +153,7 @@ class DB_odbc extends DB_common // {{{ constructor /** - * This constructor calls $this->DB_common() + * This constructor calls parent::__construct() * * @return void */ @@ -480,18 +480,6 @@ function quoteIdentifier($str) } } - // }}} - // {{{ quote() - - /** - * @deprecated Deprecated in release 1.6.0 - * @internal - */ - function quote($str) - { - return $this->quoteSmart($str); - } - // }}} // {{{ nextId() diff --git a/DB/pgsql.php b/DB/pgsql.php index 25db7440c..5d045dfda 100644 --- a/DB/pgsql.php +++ b/DB/pgsql.php @@ -6,7 +6,7 @@ * The PEAR DB driver for PHP's pgsql extension * for interacting with PostgreSQL databases * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -21,7 +21,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: pgsql.php,v 1.138 2007/09/21 13:40:41 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -43,7 +43,7 @@ * @author Daniel Convissor * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_pgsql extends DB_common @@ -148,7 +148,7 @@ class DB_pgsql extends DB_common // {{{ constructor /** - * This constructor calls $this->DB_common() + * This constructor calls parent::__construct() * * @return void */ @@ -187,12 +187,12 @@ function __construct() * Example of connecting to a new link via a socket: * * require_once 'DB.php'; - * + * * $dsn = 'pgsql://user:pass@unix(/tmp)/dbname?new_link=true'; * $options = array( * 'portability' => DB_PORTABILITY_ALL, * ); - * + * * $db = DB::connect($dsn, $options); * if (PEAR::isError($db)) { * die($db->getMessage()); @@ -325,14 +325,14 @@ function simpleQuery($query) $query = $this->modifyQuery($query); if (!$this->autocommit && $ismanip) { if ($this->transaction_opcount == 0) { - $result = @pg_exec($this->connection, 'begin;'); + $result = @pg_query($this->connection, 'begin;'); if (!$result) { return $this->pgsqlRaiseError(); } } $this->transaction_opcount++; } - $result = @pg_exec($this->connection, $query); + $result = @pg_query($this->connection, $query); if (!$result) { return $this->pgsqlRaiseError(); } @@ -348,12 +348,12 @@ function simpleQuery($query) * CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH, * GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET, * REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW, - * UNLISTEN, UPDATE, VACUUM + * UNLISTEN, UPDATE, VACUUM, WITH */ if ($ismanip) { $this->affected = @pg_affected_rows($result); return DB_OK; - } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW)\s/si', + } elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW|WITH)\s/si', $query)) { $this->row[(int)$result] = 0; // reset the row counter. @@ -465,18 +465,6 @@ function freeResult($result) return false; } - // }}} - // {{{ quote() - - /** - * @deprecated Deprecated in release 1.6.0 - * @internal - */ - function quote($str) - { - return $this->quoteSmart($str); - } - // }}} // {{{ quoteBoolean() @@ -492,7 +480,7 @@ function quote($str) function quoteBoolean($boolean) { return $boolean ? 'TRUE' : 'FALSE'; } - + // }}} // {{{ escapeSimple() @@ -610,7 +598,7 @@ function commit() if ($this->transaction_opcount > 0) { // (disabled) hack to shut up error messages from libpq.a //@fclose(@fopen("php://stderr", "w")); - $result = @pg_exec($this->connection, 'end;'); + $result = @pg_query($this->connection, 'end;'); $this->transaction_opcount = 0; if (!$result) { return $this->pgsqlRaiseError(); @@ -630,7 +618,7 @@ function commit() function rollback() { if ($this->transaction_opcount > 0) { - $result = @pg_exec($this->connection, 'abort;'); + $result = @pg_query($this->connection, 'abort;'); $this->transaction_opcount = 0; if (!$result) { return $this->pgsqlRaiseError(); @@ -796,7 +784,7 @@ function pgsqlRaiseError($errno = null) /** * Gets the DBMS' native error message produced by the last query * - * {@internal Error messages are used instead of error codes + * {@internal Error messages are used instead of error codes * in order to support older versions of PostgreSQL.}} * * @return string the DBMS' error message @@ -899,7 +887,7 @@ function tableInfo($result, $mode = null) * Probably received a table name. * Create a result resource identifier. */ - $id = @pg_exec($this->connection, "SELECT * FROM $result LIMIT 0"); + $id = @pg_query($this->connection, "SELECT * FROM $result LIMIT 0"); $got_string = true; } elseif (isset($result->result)) { /* @@ -992,7 +980,7 @@ function _pgFieldFlags($resource, $num_field, $table_name) $tableWhere = "tab.relname = '$table_name'"; } - $result = @pg_exec($this->connection, "SELECT f.attnotnull, f.atthasdef + $result = @pg_query($this->connection, "SELECT f.attnotnull, f.atthasdef FROM $from WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid @@ -1003,7 +991,7 @@ function _pgFieldFlags($resource, $num_field, $table_name) $flags = ($row[0] == 't') ? 'not_null ' : ''; if ($row[1] == 't') { - $result = @pg_exec($this->connection, "SELECT a.adsrc + $result = @pg_query($this->connection, "SELECT a.adsrc FROM $from, pg_attrdef a WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid AND f.attrelid = a.adrelid AND f.attname = '$field_name' @@ -1015,7 +1003,7 @@ function _pgFieldFlags($resource, $num_field, $table_name) } else { $flags = ''; } - $result = @pg_exec($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey + $result = @pg_query($this->connection, "SELECT i.indisunique, i.indisprimary, i.indkey FROM $from, pg_index i WHERE tab.relname = typ.typname AND typ.typrelid = f.attrelid @@ -1103,6 +1091,25 @@ function getSpecialQuery($type) } // }}} + // {{{ _checkManip() + + /** + * Checks if the given query is a manipulation query. This also takes into + * account the _next_query_manip flag and sets the _last_query_manip flag + * (and resets _next_query_manip) according to the result. + * + * @param string The query to check. + * + * @return boolean true if the query is a manipulation query, false + * otherwise + * + * @access protected + */ + function _checkManip($query) + { + return (preg_match('/^\s*(SAVEPOINT|RELEASE)\s+/i', $query) + || parent::_checkManip($query)); + } } diff --git a/DB/storage.php b/DB/storage.php index 01a038674..7d9a68ff5 100644 --- a/DB/storage.php +++ b/DB/storage.php @@ -5,7 +5,7 @@ /** * Provides an object interface to a table row * - * PHP versions 4 and 5 + * PHP version 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: @@ -18,7 +18,7 @@ * @author Stig Bakken * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: storage.php,v 1.24 2007/08/12 05:27:25 aharvey Exp $ + * @version CVS: $Id$ * @link http://pear.php.net/package/DB */ @@ -38,7 +38,7 @@ * @author Stig Bakken * @copyright 1997-2007 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version Release: 1.7.13 + * @version Release: 1.9.3 * @link http://pear.php.net/package/DB */ class DB_storage extends PEAR @@ -96,7 +96,7 @@ class DB_storage extends PEAR */ function __construct($table, $keycolumn, &$dbh, $validator = null) { - parent::__construct('DB_Error'); + $this->PEAR('DB_Error'); $this->_table = $table; $this->_keycolumn = $keycolumn; $this->_dbh = $dbh;