cvs: php4 /pear/DB common.php mysql.php oci8.php pgsql.php storage.php sybase.php /pear/DB/tests db_error.phpt db_error2.phpt db_parsedsn.phpt
/pear/tests pear_error.phpt
| From: | Stig Bakken | Date: | Thu, 19 Apr 2001 02:37:48 +0000 |
| Subject: | cvs: php4 /pear/DB common.php mysql.php oci8.php pgsql.php storage.php sybase.php /pear/DB/tests db_error.phpt db_error2.phpt db_parsedsn.phpt /pear/tests pear_error.phpt |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-45@lists.php.net to get a copy of this message | ||
ssb Wed Apr 18 19:37:48 2001 EDT
Modified files:
/php4/pear/DB common.php mysql.php oci8.php pgsql.php storage.php
sybase.php
/php4/pear/DB/tests db_error.phpt db_error2.phpt db_parsedsn.phpt
/php4/pear/tests pear_error.phpt
Log:
* DB_common now inherits PEAR and its error handling stuff
* DB_common::raiseError is now just a wrapper for PEAR::raiseError
* fixed some cast warnings in prepare/execute
* updated tests
Index: php4/pear/DB/common.php diff -u php4/pear/DB/common.php:1.44 php4/pear/DB/common.php:1.45 --- php4/pear/DB/common.php:1.44 Mon Apr 16 14:46:37 2001 +++ php4/pear/DB/common.php Wed Apr 18 19:37:47 2001 @@ -25,7 +25,7 @@ * inherited by all such. */ -class DB_common +class DB_common extends PEAR { // {{{ properties @@ -35,9 +35,6 @@ var $prepare_tokens; var $prepare_types; var $prepare_maxstmt; - var $error_mode = PEAR_ERROR_RETURN; - var $error_level = E_USER_NOTICE; - var $error_callback; var $last_query = ''; var $fetchmode = DB_FETCHMODE_ORDERED; var $options = array( @@ -69,6 +66,7 @@ function DB_common() { + $this->PEAR('DB_Error'); $this->features = array(); $this->errorcode_map = array(); $this->fetchmode = DB_FETCHMODE_ORDERED; @@ -161,98 +159,19 @@ * */ - function &raiseError($code = DB_ERROR, $mode = null, $level = null, - $debuginfo = null, $nativecode = null) + function &raiseError($code = DB_ERROR, $mode = null, $options = null, + $userinfo = null, $nativecode = null) { - if ($mode === null) { - $mode = $this->error_mode; + if ($userinfo === null) { + $userinfo = $this->last_query; } - if ($mode == PEAR_ERROR_CALLBACK) { - if (!is_string($level) && - !(is_array($level) && sizeof($level) == 2 && - is_object($level[0]) && is_string($level[1]))) { - $level = $this->error_callback; - } - } else { - if ($level === null) { - $level = $this->error_level; - } - } - - if ($debuginfo === null) { - $debuginfo = $this->last_query; - } - if ($nativecode) { - $debuginfo .= " [nativecode=$nativecode]"; + $userinfo .= " [nativecode=$nativecode]"; } - - return new DB_Error($code, $mode, $level, $debuginfo); - } - - // }}} - // {{{ setErrorHandling() - /** - * Sets how errors generated by this DB object should be handled. - * - * @param $mode int - * one of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, - * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or - * PEAR_ERROR_CALLBACK. - * - * @param $options mixed - * Ignored unless $mode is PEAR_ERROR_TRIGGER or - * PEAR_ERROR_CALLBACK. When $mode is PEAR_ERROR_TRIGGER, - * this parameter is expected to be an integer among - * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR. When - * $mode is PEAR_ERROR_CALLBACK, this parameter is expected - * to be the callback function or method. A callback - * function is a string with the name of the function, a - * callback method is an array of two elements: the element - * at index 0 is an object, and the element at index 1 is - * the name of the method to call in the object. - * - * @see PEAR_ERROR_RETURN - * @see PEAR_ERROR_PRINT - * @see PEAR_ERROR_TRIGGER - * @see PEAR_ERROR_DIE - * @see PEAR_ERROR_CALLBACK - */ - - function setErrorHandling($mode, $options = false) - { - switch ($mode) { - case PEAR_ERROR_RETURN: - case PEAR_ERROR_PRINT: - case PEAR_ERROR_TRIGGER: - case PEAR_ERROR_DIE: - $this->error_mode = $mode; - - if (!$options) { - $this->error_level = E_USER_NOTICE; - } else { - $this->error_level = $options; - } - break; - - case PEAR_ERROR_CALLBACK: - $this->error_mode = $mode; - if (is_string($options) || - (is_array($options) && sizeof($options) == 2 && - is_object($options[0]) && is_string($options[1]))) { - $this->error_callback = $options; - } else { - trigger_error("invalid error callback", E_USER_WARNING); - } - $this->error_level = PEAR_ERROR_RETURN; - break; - - default: - trigger_error("invalid error mode", E_USER_WARNING); - break; - } + return parent::raiseError(null, $code, $mode, $options, $userinfo, + null, true); } // }}} Index: php4/pear/DB/mysql.php diff -u php4/pear/DB/mysql.php:1.55 php4/pear/DB/mysql.php:1.56 --- php4/pear/DB/mysql.php:1.55 Sat Apr 14 15:43:08 2001 +++ php4/pear/DB/mysql.php Wed Apr 18 19:37:47 2001 @@ -262,12 +262,12 @@ return mysql_free_result($result); } - if (!isset($this->prepare_tokens[$result])) { + if (!isset($this->prepare_tokens[(int)$result])) { return false; } - unset($this->prepare_tokens[$result]); - unset($this->prepare_types[$result]); + unset($this->prepare_tokens[(int)$result]); + unset($this->prepare_types[(int)$result]); return true; } Index: php4/pear/DB/oci8.php diff -u php4/pear/DB/oci8.php:1.22 php4/pear/DB/oci8.php:1.23 --- php4/pear/DB/oci8.php:1.22 Tue Mar 27 16:54:05 2001 +++ php4/pear/DB/oci8.php Wed Apr 18 19:37:47 2001 @@ -226,12 +226,12 @@ if (is_resource($result)) { return @OCIFreeStatement($result); } - if (!isset($this->prepare_tokens[$result])) { + if (!isset($this->prepare_tokens[(int)$result])) { return false; } - unset($this->prepare_tokens[$result]); - unset($this->prepare_types[$result]); - unset($this->manip_query[$result]); + unset($this->prepare_tokens[(int)$result]); + unset($this->prepare_types[(int)$result]); + unset($this->manip_query[(int)$result]); return true; } @@ -338,7 +338,7 @@ $newquery = $this->modifyQuery($newquery); $stmt = @OCIParse($this->connection, $newquery); $this->prepare_types[$stmt] = $types; - $this->manip_query[$stmt] = DB::isManip($query); + $this->manip_query[(int)$stmt] = DB::isManip($query); return $stmt; } @@ -391,7 +391,7 @@ return $this->oci8RaiseError($stmt); } $this->last_stmt = $stmt; - if ($this->manip_query[$stmt]) { + if ($this->manip_query[(int)$stmt]) { return $DB_OK; } else { return $stmt; Index: php4/pear/DB/pgsql.php diff -u php4/pear/DB/pgsql.php:1.37 php4/pear/DB/pgsql.php:1.38 --- php4/pear/DB/pgsql.php:1.37 Wed Apr 4 15:55:09 2001 +++ php4/pear/DB/pgsql.php Wed Apr 18 19:37:47 2001 @@ -297,13 +297,13 @@ if (is_resource($result)) { return @pg_freeresult($result); } - if (!isset($this->prepare_tokens[$result])) { + if (!isset($this->prepare_tokens[(int)$result])) { return false; } - unset($this->prepare_tokens[$result]); - unset($this->prepare_types[$result]); - unset($this->row[$result]); - unset($this->num_rows[$result]); + unset($this->prepare_tokens[(int)$result]); + unset($this->prepare_types[(int)$result]); + unset($this->row[(int)$result]); + unset($this->num_rows[(int)$result]); $this->affected = 0; return true; } Index: php4/pear/DB/storage.php diff -u php4/pear/DB/storage.php:1.13 php4/pear/DB/storage.php:1.14 --- php4/pear/DB/storage.php:1.13 Mon Apr 16 14:48:53 2001 +++ php4/pear/DB/storage.php Wed Apr 18 19:37:47 2001 @@ -75,7 +75,7 @@ */ function DB_storage($table, $keycolumn, &$dbh) { - $this->PEAR(); + $this->PEAR('DB_Error'); $this->_table = $table; $this->_keycolumn = $keycolumn; $this->_dbh = $dbh; @@ -117,7 +117,7 @@ $whereclause = $this->_keycolumn . ' = '; if (is_string($keyval)) { $whereclause .= "'" . - $this->_dbh->quoteString($keyval[$i]) . "'"; + $this->_dbh->quoteString($keyval) . "'"; } else { $whereclause .= $keyval; } @@ -151,11 +151,12 @@ return $row; } if (empty($row)) { - return new DB_Error(DB_ERROR_NOT_FOUND, null, null, null, $query); + return $this->raiseError(null, DB_ERROR_NOT_FOUND, null, null, + $query, null, true); } - while (list($key, $value) = each($row)) { + foreach ($row as $key => $value) { $this->_properties[$key] = true; - $this->$key = &$value; + $this->$key = $value; } return DB_OK; } Index: php4/pear/DB/sybase.php diff -u php4/pear/DB/sybase.php:1.16 php4/pear/DB/sybase.php:1.17 --- php4/pear/DB/sybase.php:1.16 Mon Apr 2 17:23:46 2001 +++ php4/pear/DB/sybase.php Wed Apr 18 19:37:47 2001 @@ -16,7 +16,7 @@ // | Authors: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: sybase.php,v 1.16 2001/04/03 00:23:46 cox Exp $ +// $Id: sybase.php,v 1.17 2001/04/19 02:37:47 ssb Exp $ // // Database independent query interface definition for PHP's Sybase // extension. @@ -136,11 +136,11 @@ if (is_resource($result)) { return @sybase_free_result($result); } - if (!isset($this->prepare_tokens[$result])) { + if (!isset($this->prepare_tokens[(int)$result])) { return false; } - unset($this->prepare_tokens[$result]); - unset($this->prepare_types[$result]); + unset($this->prepare_tokens[(int)$result]); + unset($this->prepare_types[(int)$result]); return true; } Index: php4/pear/DB/tests/db_error.phpt diff -u php4/pear/DB/tests/db_error.phpt:1.7 php4/pear/DB/tests/db_error.phpt:1.8 --- php4/pear/DB/tests/db_error.phpt:1.7 Sat Mar 10 23:58:19 2001 +++ php4/pear/DB/tests/db_error.phpt Wed Apr 18 19:37:47 2001 @@ -35,23 +35,23 @@ --POST-- --EXPECT-- testing different error codes... -[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: test error" code=-1 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: no error" code=0 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: syntax error" code=-2 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: division by zero" code=-13 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_warning: message="DB Warning: unknown warning" code=-1000 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_warning: message="DB Warning: test warning" code=0 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_warning: message="DB Warning: read only" code=-1001 mode=return level=notice prefix="" prepend="" append="" debug=""] +[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: test error" code=-1 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: no error" code=0 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: syntax error" code=-2 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: division by zero" code=-13 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_warning: message="DB Warning: unknown warning" code=-1000 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_warning: message="DB Warning: test warning" code=0 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_warning: message="DB Warning: read only" code=-1001 mode=return level=notice prefix="" prepend="" append="" info=""] testing different error modes... -DB Error: unknown error[db_error: message="DB Error: unknown error" code=-1 mode=print level=notice prefix="" prepend="" append="" debug=""] +DB Error: unknown error[db_error: message="DB Error: unknown error" code=-1 mode=print level=notice prefix="" prepend="" append="" info=""] <br> -<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>353</b><br> +<b>Notice</b>: DB Error: syntax error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> testing different error serverities... <br> -<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>353</b><br> +<b>Notice</b>: DB Error: syntax error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> <br> -<b>Warning</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>353</b><br> +<b>Warning</b>: DB Error: syntax error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> <br> -<b>Fatal error</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>353</b><br> +<b>Fatal error</b>: DB Error: syntax error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> Index: php4/pear/DB/tests/db_error2.phpt diff -u php4/pear/DB/tests/db_error2.phpt:1.7 php4/pear/DB/tests/db_error2.phpt:1.8 --- php4/pear/DB/tests/db_error2.phpt:1.7 Sat Mar 10 23:58:19 2001 +++ php4/pear/DB/tests/db_error2.phpt Wed Apr 18 19:37:47 2001 @@ -9,6 +9,9 @@ function myfunc(&$obj) { print "myfunc here, obj=".$obj->toString()."\n"; } +function myfunc2(&$obj) { + print "myfunc2 here, obj=".$obj->toString()."\n"; +} class myclass { function myfunc(&$obj) { print "myclass::myfunc here, obj=".$obj->toString()."\n"; @@ -17,28 +20,38 @@ $obj = new myclass; $dbh = DB::factory("mysql"); + print "default: "; $e = $dbh->raiseError("return testing error"); print $e->toString() . "\n"; + +print "global default: "; +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "myfunc2"); +$e = $dbh->raiseError("global default test"); + $dbh->setErrorHandling(PEAR_ERROR_PRINT); print "mode=print: "; $e = $dbh->raiseError("print testing error"); print "\n"; + $dbh->setErrorHandling(PEAR_ERROR_TRIGGER); print "mode=trigger: "; $e = $dbh->raiseError("trigger testing error"); + $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, "myfunc"); print "mode=function callback: "; $e = $dbh->raiseError("function callback testing error"); + $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, array($obj, "myfunc")); print "mode=object callback: "; $e = $dbh->raiseError("object callback testing error"); ?> --EXPECT-- -default: [db_error: message="DB Error: return testing error" code=-1 mode=return level=notice prefix="" prepend="" append="" debug=""] +default: [db_error: message="DB Error: return testing error" code=-1 mode=return level=notice prefix="" prepend="" append="" info=""] +global default: myfunc2 here, obj=[db_error: message="DB Error: global default test" code=-1 mode=callback callback=myfunc2 prefix="" prepend="" append="" info=""] mode=print: DB Error: print testing error mode=trigger: <br> -<b>Notice</b>: DB Error: trigger testing error in <b>PEAR.php</b> on line <b>353</b><br> -mode=function callback: myfunc here, obj=[db_error: message="DB Error: function callback testing error" code=-1 mode=callback callback=myfunc prefix="" prepend="" append="" debug=""] -mode=object callback: myclass::myfunc here, obj=[db_error: message="DB Error: object callback testing error" code=-1 mode=callback callback=myclass::myfunc prefix="" prepend="" append="" debug=""] +<b>Notice</b>: DB Error: trigger testing error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +mode=function callback: myfunc here, obj=[db_error: message="DB Error: function callback testing error" code=-1 mode=callback callback=myfunc prefix="" prepend="" append="" info=""] +mode=object callback: myclass::myfunc here, obj=[db_error: message="DB Error: object callback testing error" code=-1 mode=callback callback=myclass::myfunc prefix="" prepend="" append="" info=""] Index: php4/pear/DB/tests/db_parsedsn.phpt diff -u php4/pear/DB/tests/db_parsedsn.phpt:1.2 php4/pear/DB/tests/db_parsedsn.phpt:1.3 --- php4/pear/DB/tests/db_parsedsn.phpt:1.2 Tue Jan 30 00:34:55 2001 +++ php4/pear/DB/tests/db_parsedsn.phpt Wed Apr 18 19:37:47 2001 @@ -30,7 +30,7 @@ --POST-- --EXPECT-- testing DB::parseDSN... -mysql,,,,,, +mysql,mysql,,,,, odbc,mssql,,,,, mysql,mysql,,localhost,,, mysql,mysql,,remote.host.com,db,, Index: php4/pear/tests/pear_error.phpt diff -u php4/pear/tests/pear_error.phpt:1.7 php4/pear/tests/pear_error.phpt:1.8 --- php4/pear/tests/pear_error.phpt:1.7 Mon Apr 16 18:51:27 2001 +++ php4/pear/tests/pear_error.phpt Wed Apr 18 19:37:47 2001 @@ -113,16 +113,16 @@ mode=callback(function): errorhandler function called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorhandler prefix="" prepend="" append="" info=""] mode=callback(method): errorhandler method called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorclass::errorhandler prefix="" prepend="" append="" info=""] mode=print&trigger: test error<br> -<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> [pear_error: message="test error" code=-42 mode=print|trigger level=notice prefix="" prepend="" append="" info=""] mode=trigger: <br> -<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> [pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append="" info=""] mode=trigger,level=notice: <br> -<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> [pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append="" info=""] mode=trigger,level=warning: <br> -<b>Warning</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Warning</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> [pear_error: message="test error" code=-42 mode=trigger level=warning prefix="" prepend="" append="" info=""] mode=trigger,level=error: <br> -<b>Fatal error</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Fatal error</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br>
Index: php4/pear/DB/common.php diff -u php4/pear/DB/common.php:1.44 php4/pear/DB/common.php:1.45 --- php4/pear/DB/common.php:1.44 Mon Apr 16 14:46:37 2001 +++ php4/pear/DB/common.php Wed Apr 18 19:37:47 2001 @@ -25,7 +25,7 @@ * inherited by all such. */ -class DB_common +class DB_common extends PEAR { // {{{ properties @@ -35,9 +35,6 @@ var $prepare_tokens; var $prepare_types; var $prepare_maxstmt; - var $error_mode = PEAR_ERROR_RETURN; - var $error_level = E_USER_NOTICE; - var $error_callback; var $last_query = ''; var $fetchmode = DB_FETCHMODE_ORDERED; var $options = array( @@ -69,6 +66,7 @@ function DB_common() { + $this->PEAR('DB_Error'); $this->features = array(); $this->errorcode_map = array(); $this->fetchmode = DB_FETCHMODE_ORDERED; @@ -161,98 +159,19 @@ * */ - function &raiseError($code = DB_ERROR, $mode = null, $level = null, - $debuginfo = null, $nativecode = null) + function &raiseError($code = DB_ERROR, $mode = null, $options = null, + $userinfo = null, $nativecode = null) { - if ($mode === null) { - $mode = $this->error_mode; + if ($userinfo === null) { + $userinfo = $this->last_query; } - if ($mode == PEAR_ERROR_CALLBACK) { - if (!is_string($level) && - !(is_array($level) && sizeof($level) == 2 && - is_object($level[0]) && is_string($level[1]))) { - $level = $this->error_callback; - } - } else { - if ($level === null) { - $level = $this->error_level; - } - } - - if ($debuginfo === null) { - $debuginfo = $this->last_query; - } - if ($nativecode) { - $debuginfo .= " [nativecode=$nativecode]"; + $userinfo .= " [nativecode=$nativecode]"; } - - return new DB_Error($code, $mode, $level, $debuginfo); - } - - // }}} - // {{{ setErrorHandling() - /** - * Sets how errors generated by this DB object should be handled. - * - * @param $mode int - * one of PEAR_ERROR_RETURN, PEAR_ERROR_PRINT, - * PEAR_ERROR_TRIGGER, PEAR_ERROR_DIE or - * PEAR_ERROR_CALLBACK. - * - * @param $options mixed - * Ignored unless $mode is PEAR_ERROR_TRIGGER or - * PEAR_ERROR_CALLBACK. When $mode is PEAR_ERROR_TRIGGER, - * this parameter is expected to be an integer among - * E_USER_NOTICE, E_USER_WARNING or E_USER_ERROR. When - * $mode is PEAR_ERROR_CALLBACK, this parameter is expected - * to be the callback function or method. A callback - * function is a string with the name of the function, a - * callback method is an array of two elements: the element - * at index 0 is an object, and the element at index 1 is - * the name of the method to call in the object. - * - * @see PEAR_ERROR_RETURN - * @see PEAR_ERROR_PRINT - * @see PEAR_ERROR_TRIGGER - * @see PEAR_ERROR_DIE - * @see PEAR_ERROR_CALLBACK - */ - - function setErrorHandling($mode, $options = false) - { - switch ($mode) { - case PEAR_ERROR_RETURN: - case PEAR_ERROR_PRINT: - case PEAR_ERROR_TRIGGER: - case PEAR_ERROR_DIE: - $this->error_mode = $mode; - - if (!$options) { - $this->error_level = E_USER_NOTICE; - } else { - $this->error_level = $options; - } - break; - - case PEAR_ERROR_CALLBACK: - $this->error_mode = $mode; - if (is_string($options) || - (is_array($options) && sizeof($options) == 2 && - is_object($options[0]) && is_string($options[1]))) { - $this->error_callback = $options; - } else { - trigger_error("invalid error callback", E_USER_WARNING); - } - $this->error_level = PEAR_ERROR_RETURN; - break; - - default: - trigger_error("invalid error mode", E_USER_WARNING); - break; - } + return parent::raiseError(null, $code, $mode, $options, $userinfo, + null, true); } // }}} Index: php4/pear/DB/mysql.php diff -u php4/pear/DB/mysql.php:1.55 php4/pear/DB/mysql.php:1.56 --- php4/pear/DB/mysql.php:1.55 Sat Apr 14 15:43:08 2001 +++ php4/pear/DB/mysql.php Wed Apr 18 19:37:47 2001 @@ -262,12 +262,12 @@ return mysql_free_result($result); } - if (!isset($this->prepare_tokens[$result])) { + if (!isset($this->prepare_tokens[(int)$result])) { return false; } - unset($this->prepare_tokens[$result]); - unset($this->prepare_types[$result]); + unset($this->prepare_tokens[(int)$result]); + unset($this->prepare_types[(int)$result]); return true; } Index: php4/pear/DB/oci8.php diff -u php4/pear/DB/oci8.php:1.22 php4/pear/DB/oci8.php:1.23 --- php4/pear/DB/oci8.php:1.22 Tue Mar 27 16:54:05 2001 +++ php4/pear/DB/oci8.php Wed Apr 18 19:37:47 2001 @@ -226,12 +226,12 @@ if (is_resource($result)) { return @OCIFreeStatement($result); } - if (!isset($this->prepare_tokens[$result])) { + if (!isset($this->prepare_tokens[(int)$result])) { return false; } - unset($this->prepare_tokens[$result]); - unset($this->prepare_types[$result]); - unset($this->manip_query[$result]); + unset($this->prepare_tokens[(int)$result]); + unset($this->prepare_types[(int)$result]); + unset($this->manip_query[(int)$result]); return true; } @@ -338,7 +338,7 @@ $newquery = $this->modifyQuery($newquery); $stmt = @OCIParse($this->connection, $newquery); $this->prepare_types[$stmt] = $types; - $this->manip_query[$stmt] = DB::isManip($query); + $this->manip_query[(int)$stmt] = DB::isManip($query); return $stmt; } @@ -391,7 +391,7 @@ return $this->oci8RaiseError($stmt); } $this->last_stmt = $stmt; - if ($this->manip_query[$stmt]) { + if ($this->manip_query[(int)$stmt]) { return $DB_OK; } else { return $stmt; Index: php4/pear/DB/pgsql.php diff -u php4/pear/DB/pgsql.php:1.37 php4/pear/DB/pgsql.php:1.38 --- php4/pear/DB/pgsql.php:1.37 Wed Apr 4 15:55:09 2001 +++ php4/pear/DB/pgsql.php Wed Apr 18 19:37:47 2001 @@ -297,13 +297,13 @@ if (is_resource($result)) { return @pg_freeresult($result); } - if (!isset($this->prepare_tokens[$result])) { + if (!isset($this->prepare_tokens[(int)$result])) { return false; } - unset($this->prepare_tokens[$result]); - unset($this->prepare_types[$result]); - unset($this->row[$result]); - unset($this->num_rows[$result]); + unset($this->prepare_tokens[(int)$result]); + unset($this->prepare_types[(int)$result]); + unset($this->row[(int)$result]); + unset($this->num_rows[(int)$result]); $this->affected = 0; return true; } Index: php4/pear/DB/storage.php diff -u php4/pear/DB/storage.php:1.13 php4/pear/DB/storage.php:1.14 --- php4/pear/DB/storage.php:1.13 Mon Apr 16 14:48:53 2001 +++ php4/pear/DB/storage.php Wed Apr 18 19:37:47 2001 @@ -75,7 +75,7 @@ */ function DB_storage($table, $keycolumn, &$dbh) { - $this->PEAR(); + $this->PEAR('DB_Error'); $this->_table = $table; $this->_keycolumn = $keycolumn; $this->_dbh = $dbh; @@ -117,7 +117,7 @@ $whereclause = $this->_keycolumn . ' = '; if (is_string($keyval)) { $whereclause .= "'" . - $this->_dbh->quoteString($keyval[$i]) . "'"; + $this->_dbh->quoteString($keyval) . "'"; } else { $whereclause .= $keyval; } @@ -151,11 +151,12 @@ return $row; } if (empty($row)) { - return new DB_Error(DB_ERROR_NOT_FOUND, null, null, null, $query); + return $this->raiseError(null, DB_ERROR_NOT_FOUND, null, null, + $query, null, true); } - while (list($key, $value) = each($row)) { + foreach ($row as $key => $value) { $this->_properties[$key] = true; - $this->$key = &$value; + $this->$key = $value; } return DB_OK; } Index: php4/pear/DB/sybase.php diff -u php4/pear/DB/sybase.php:1.16 php4/pear/DB/sybase.php:1.17 --- php4/pear/DB/sybase.php:1.16 Mon Apr 2 17:23:46 2001 +++ php4/pear/DB/sybase.php Wed Apr 18 19:37:47 2001 @@ -16,7 +16,7 @@ // | Authors: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: sybase.php,v 1.16 2001/04/03 00:23:46 cox Exp $ +// $Id: sybase.php,v 1.17 2001/04/19 02:37:47 ssb Exp $ // // Database independent query interface definition for PHP's Sybase // extension. @@ -136,11 +136,11 @@ if (is_resource($result)) { return @sybase_free_result($result); } - if (!isset($this->prepare_tokens[$result])) { + if (!isset($this->prepare_tokens[(int)$result])) { return false; } - unset($this->prepare_tokens[$result]); - unset($this->prepare_types[$result]); + unset($this->prepare_tokens[(int)$result]); + unset($this->prepare_types[(int)$result]); return true; } Index: php4/pear/DB/tests/db_error.phpt diff -u php4/pear/DB/tests/db_error.phpt:1.7 php4/pear/DB/tests/db_error.phpt:1.8 --- php4/pear/DB/tests/db_error.phpt:1.7 Sat Mar 10 23:58:19 2001 +++ php4/pear/DB/tests/db_error.phpt Wed Apr 18 19:37:47 2001 @@ -35,23 +35,23 @@ --POST-- --EXPECT-- testing different error codes... -[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: test error" code=-1 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: no error" code=0 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: syntax error" code=-2 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_error: message="DB Error: division by zero" code=-13 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_warning: message="DB Warning: unknown warning" code=-1000 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_warning: message="DB Warning: test warning" code=0 mode=return level=notice prefix="" prepend="" append="" debug=""] -[db_warning: message="DB Warning: read only" code=-1001 mode=return level=notice prefix="" prepend="" append="" debug=""] +[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: test error" code=-1 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: no error" code=0 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: syntax error" code=-2 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_error: message="DB Error: division by zero" code=-13 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_warning: message="DB Warning: unknown warning" code=-1000 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_warning: message="DB Warning: test warning" code=0 mode=return level=notice prefix="" prepend="" append="" info=""] +[db_warning: message="DB Warning: read only" code=-1001 mode=return level=notice prefix="" prepend="" append="" info=""] testing different error modes... -DB Error: unknown error[db_error: message="DB Error: unknown error" code=-1 mode=print level=notice prefix="" prepend="" append="" debug=""] +DB Error: unknown error[db_error: message="DB Error: unknown error" code=-1 mode=print level=notice prefix="" prepend="" append="" info=""] <br> -<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>353</b><br> +<b>Notice</b>: DB Error: syntax error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> testing different error serverities... <br> -<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>353</b><br> +<b>Notice</b>: DB Error: syntax error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> <br> -<b>Warning</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>353</b><br> +<b>Warning</b>: DB Error: syntax error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> <br> -<b>Fatal error</b>: DB Error: syntax error in <b>PEAR.php</b> on line <b>353</b><br> +<b>Fatal error</b>: DB Error: syntax error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> Index: php4/pear/DB/tests/db_error2.phpt diff -u php4/pear/DB/tests/db_error2.phpt:1.7 php4/pear/DB/tests/db_error2.phpt:1.8 --- php4/pear/DB/tests/db_error2.phpt:1.7 Sat Mar 10 23:58:19 2001 +++ php4/pear/DB/tests/db_error2.phpt Wed Apr 18 19:37:47 2001 @@ -9,6 +9,9 @@ function myfunc(&$obj) { print "myfunc here, obj=".$obj->toString()."\n"; } +function myfunc2(&$obj) { + print "myfunc2 here, obj=".$obj->toString()."\n"; +} class myclass { function myfunc(&$obj) { print "myclass::myfunc here, obj=".$obj->toString()."\n"; @@ -17,28 +20,38 @@ $obj = new myclass; $dbh = DB::factory("mysql"); + print "default: "; $e = $dbh->raiseError("return testing error"); print $e->toString() . "\n"; + +print "global default: "; +PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "myfunc2"); +$e = $dbh->raiseError("global default test"); + $dbh->setErrorHandling(PEAR_ERROR_PRINT); print "mode=print: "; $e = $dbh->raiseError("print testing error"); print "\n"; + $dbh->setErrorHandling(PEAR_ERROR_TRIGGER); print "mode=trigger: "; $e = $dbh->raiseError("trigger testing error"); + $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, "myfunc"); print "mode=function callback: "; $e = $dbh->raiseError("function callback testing error"); + $dbh->setErrorHandling(PEAR_ERROR_CALLBACK, array($obj, "myfunc")); print "mode=object callback: "; $e = $dbh->raiseError("object callback testing error"); ?> --EXPECT-- -default: [db_error: message="DB Error: return testing error" code=-1 mode=return level=notice prefix="" prepend="" append="" debug=""] +default: [db_error: message="DB Error: return testing error" code=-1 mode=return level=notice prefix="" prepend="" append="" info=""] +global default: myfunc2 here, obj=[db_error: message="DB Error: global default test" code=-1 mode=callback callback=myfunc2 prefix="" prepend="" append="" info=""] mode=print: DB Error: print testing error mode=trigger: <br> -<b>Notice</b>: DB Error: trigger testing error in <b>PEAR.php</b> on line <b>353</b><br> -mode=function callback: myfunc here, obj=[db_error: message="DB Error: function callback testing error" code=-1 mode=callback callback=myfunc prefix="" prepend="" append="" debug=""] -mode=object callback: myclass::myfunc here, obj=[db_error: message="DB Error: object callback testing error" code=-1 mode=callback callback=myclass::myfunc prefix="" prepend="" append="" debug=""] +<b>Notice</b>: DB Error: trigger testing error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +mode=function callback: myfunc here, obj=[db_error: message="DB Error: function callback testing error" code=-1 mode=callback callback=myfunc prefix="" prepend="" append="" info=""] +mode=object callback: myclass::myfunc here, obj=[db_error: message="DB Error: object callback testing error" code=-1 mode=callback callback=myclass::myfunc prefix="" prepend="" append="" info=""] Index: php4/pear/DB/tests/db_parsedsn.phpt diff -u php4/pear/DB/tests/db_parsedsn.phpt:1.2 php4/pear/DB/tests/db_parsedsn.phpt:1.3 --- php4/pear/DB/tests/db_parsedsn.phpt:1.2 Tue Jan 30 00:34:55 2001 +++ php4/pear/DB/tests/db_parsedsn.phpt Wed Apr 18 19:37:47 2001 @@ -30,7 +30,7 @@ --POST-- --EXPECT-- testing DB::parseDSN... -mysql,,,,,, +mysql,mysql,,,,, odbc,mssql,,,,, mysql,mysql,,localhost,,, mysql,mysql,,remote.host.com,db,, Index: php4/pear/tests/pear_error.phpt diff -u php4/pear/tests/pear_error.phpt:1.7 php4/pear/tests/pear_error.phpt:1.8 --- php4/pear/tests/pear_error.phpt:1.7 Mon Apr 16 18:51:27 2001 +++ php4/pear/tests/pear_error.phpt Wed Apr 18 19:37:47 2001 @@ -113,16 +113,16 @@ mode=callback(function): errorhandler function called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorhandler prefix="" prepend="" append="" info=""] mode=callback(method): errorhandler method called, obj=[pear_error: message="test error" code=-42 mode=callback callback=errorclass::errorhandler prefix="" prepend="" append="" info=""] mode=print&trigger: test error<br> -<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> [pear_error: message="test error" code=-42 mode=print|trigger level=notice prefix="" prepend="" append="" info=""] mode=trigger: <br> -<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> [pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append="" info=""] mode=trigger,level=notice: <br> -<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Notice</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> [pear_error: message="test error" code=-42 mode=trigger level=notice prefix="" prepend="" append="" info=""] mode=trigger,level=warning: <br> -<b>Warning</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Warning</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br> [pear_error: message="test error" code=-42 mode=trigger level=warning prefix="" prepend="" append="" info=""] mode=trigger,level=error: <br> -<b>Fatal error</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>413</b><br> +<b>Fatal error</b>: test error in <b>/usr/local/lib/php/PEAR.php</b> on line <b>411</b><br>