Skip to content

Commit

Permalink
Upgrade DB package to be version 1.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 committed Dec 26, 2019
1 parent 4f0e6b5 commit b7ebb28
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 133 deletions.
71 changes: 43 additions & 28 deletions DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,7 +20,7 @@
* @author Daniel Convissor <danielc@php.net>
* @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
*/

Expand Down Expand Up @@ -49,9 +49,7 @@
/**
* Unkown error
*/
if (!defined('DB_ERROR')) {
define('DB_ERROR', -1);
}
define('DB_ERROR', -1);

/**
* Syntax error
Expand Down Expand Up @@ -442,12 +440,12 @@
* @author Daniel Convissor <danielc@php.net>
* @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
Expand All @@ -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);
Expand Down Expand Up @@ -496,7 +494,7 @@ function &factory($type, $options = false)
}

// }}}
// {{{ &connect()
// {{{ connect()

/**
* Create a new DB object including a connection to the specified database
Expand Down Expand Up @@ -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'];
Expand All @@ -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;
}
Expand Down Expand Up @@ -593,7 +591,7 @@ static function &connect($dsn, $options = array())
*/
function apiVersion()
{
return '1.7.13';
return '1.9.3';
}

// }}}
Expand All @@ -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');
}

// }}}
Expand All @@ -621,7 +619,7 @@ static function isError($value)
*
* @return bool whether $value is a DB_<driver> object
*/
function isConnection($value)
public static function isConnection($value)
{
return (is_object($value) &&
is_subclass_of($value, 'db_common') &&
Expand All @@ -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;
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -972,7 +970,7 @@ function getDSNString($dsn, $hidePassword) {
* @author Stig Bakken <ssb@php.net>
* @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
Expand Down Expand Up @@ -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
);
}
// }}}
}

Expand All @@ -1019,7 +1031,7 @@ function __construct($code = DB_ERROR, $mode = PEAR_ERROR_RETURN,
* @author Stig Bakken <ssb@php.net>
* @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
Expand Down Expand Up @@ -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;
}

// }}}
Expand Down Expand Up @@ -1481,7 +1496,7 @@ function getRowCounter()
* @author Stig Bakken <ssb@php.net>
* @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()
*/
Expand Down
52 changes: 33 additions & 19 deletions DB/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -20,7 +20,7 @@
* @author Daniel Convissor <danielc@php.net>
* @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
*/

Expand All @@ -42,7 +42,7 @@
* @author Daniel Convissor <danielc@php.net>
* @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
Expand Down Expand Up @@ -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']);
}
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -284,8 +284,7 @@ function quoteString($string)
*/
function quote($string = null)
{
return ($string === null) ? 'NULL'
: "'" . str_replace("'", "''", $string) . "'";
return $this->quoteSmart($string);
}

// }}}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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');
}

// }}}

}

/*
Expand Down
Loading

0 comments on commit b7ebb28

Please sign in to comment.