cvs: php4 /pear PEAR.php.in /pear/DB .cvsignore common.php ibase.php msql.php mssql.php mysql.php oci8.php odbc.php pgsql.php sybase.php
/pear/DB/tests db_error.phpt db_error2.phpt db_factory.phpt db_parsedsn.phpt /pear/tests DB_Error.phpt DB_factory.phpt DB_parseDSN.phpt pear1.phpt
pear_error.phpt pear_error2.phpt pear_error_callback.phpt
| From: | Stig Bakken | Date: | Sat, 09 Sep 2000 02:39:57 +0000 |
| Subject: | cvs: php4 /pear PEAR.php.in /pear/DB .cvsignore common.php ibase.php msql.php mssql.php mysql.php oci8.php odbc.php pgsql.php sybase.php /pear/DB/tests db_error.phpt db_error2.phpt db_factory.phpt db_parsedsn.phpt /pear/tests DB_Error.phpt DB_factory.phpt DB_parseDSN.phpt pear1.phpt pear_error.phpt pear_error2.phpt pear_error_callback.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-1656@lists.php.net to get a copy of this message | ||
ssb Fri Sep 8 19:39:57 2000 EDT
Added files:
/php4/pear/DB .cvsignore
/php4/pear/DB/tests db_error.phpt db_error2.phpt db_factory.phpt
db_parsedsn.phpt
/php4/pear/tests pear1.phpt pear_error.phpt pear_error2.phpt
pear_error_callback.phpt
Removed files:
/php4/pear/tests DB_Error.phpt DB_factory.phpt DB_parseDSN.phpt
Modified files:
/php4/pear PEAR.php.in
/php4/pear/DB common.php ibase.php msql.php mssql.php mysql.php
oci8.php odbc.php pgsql.php sybase.php
Log:
@Added a more configurable error reporting interface to DB.
Added a more configurable error reporting interface to DB.
Also added some more tests, and moved the DB tests to pear/DB/tests.
#Usage example that prints and exits on every error:
#$dbh = DB::connect($dsn);
#$dbh->setErrorHandling(PEAR_ERROR_DIE);
#
#Example with plain callback function:
#$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, "errorHandler");
#
#Example with object callback function:
#$dbh->setErrorHandling(PEAR_ERROR_CALLBACK, array($obj, "errorHandler"));
#
#Handler functions/methods are called with the error object as a parameter.
#
Index: php4/pear/PEAR.php.in
diff -u php4/pear/PEAR.php.in:1.5 php4/pear/PEAR.php.in:1.6
--- php4/pear/PEAR.php.in:1.5 Thu Sep 7 09:36:22 2000
+++ php4/pear/PEAR.php.in Fri Sep 8 19:39:56 2000
@@ -17,13 +17,14 @@
// | Stig Bakken <ssb@fast.no> |
// +----------------------------------------------------------------------+
//
-// $Id: PEAR.php.in,v 1.5 2000/09/07 16:36:22 andrei Exp $
+// $Id: PEAR.php.in,v 1.6 2000/09/09 02:39:56 ssb Exp $
//
define('PEAR_ERROR_RETURN', 0);
define('PEAR_ERROR_PRINT', 1);
define('PEAR_ERROR_TRIGGER', 2);
define('PEAR_ERROR_DIE', 3);
+define('PEAR_ERROR_CALLBACK', 4);
define('PHP_BINDIR', '@prefix@/bin');
define('PEAR_INSTALL_DIR', '@PEAR_INSTALLDIR@');
@@ -91,6 +92,10 @@
* @access public
*/
function _PEAR() {
+ if ($this->_debug) {
+ printf("PEAR destructor called, class=%s\n",
+ get_class($this));
+ }
}
// }}}
@@ -136,7 +141,6 @@
{
// {{{ properties
- var $classname = '';
var $error_message_prefix = '';
var $error_prepend = '';
var $error_append = '';
@@ -159,8 +163,17 @@
* PEAR_Error constructor
*
* @param $message error message
+ *
* @param $code (optional) error code
*
+ * @param $mode (optional) error mode, one of: PEAR_ERROR_RETURN,
+ * PEAR_ERROR_PRINT, PEAR_ERROR_DIE, PEAR_ERROR_TRIGGER or
+ * PEAR_ERROR_CALLBACK
+ *
+ * @param $level (optional) error level, _OR_ in the case of
+ * PEAR_ERROR_CALLBACK, the callback function or object/method
+ * tuple.
+ *
*/
function PEAR_Error($message = 'unknown error',
$code = 0,
@@ -170,9 +183,12 @@
$this->message = $message;
$this->code = $code;
$this->mode = $mode;
- $this->level = $level;
- if (!$this->classname) {
- $this->classname = get_class($this);
+ if ($mode == PEAR_ERROR_CALLBACK) {
+ $this->level = E_USER_NOTICE;
+ $this->callback = $level;
+ } else {
+ $this->level = $level;
+ $this->callback = false;
}
switch ($this->mode) {
case PEAR_ERROR_PRINT:
@@ -184,6 +200,18 @@
case PEAR_ERROR_DIE:
die($this->getMessage());
break;
+ case PEAR_ERROR_CALLBACK:
+ if (is_string($this->callback) && strlen($this->callback)) {
+ call_user_func($this->callback, $this);
+ } elseif (is_array($this->callback) &&
+ sizeof($this->callback) == 2 &&
+ is_object($this->callback[0]) &&
+ is_string($this->callback[1]) &&
+ strlen($this->callback[1])) {
+ call_user_method($this->callback[1], $this->callback[0],
+ $this);
+ }
+ break;
case PEAR_ERROR_RETURN:
default:
break;
@@ -191,6 +219,20 @@
}
// }}}
+ // {{{ getMode()
+
+ function getMode() {
+ return $this->mode;
+ }
+
+ // }}}
+ // {{{ getCallback()
+
+ function getCallback() {
+ return $this->callback;
+ }
+
+ // }}}
// {{{ getMessage()
@@ -214,9 +256,9 @@
*
* @return int error code
*/
- function getCode ()
+ function getCode()
{
- return ($this->code);
+ return $this->code;
}
// }}}
@@ -229,7 +271,7 @@
*/
function getType ()
{
- return $this->classname;
+ return get_class($this);
}
// }}}
@@ -244,7 +286,8 @@
$modes = array(PEAR_ERROR_RETURN => "return",
PEAR_ERROR_PRINT => "print",
PEAR_ERROR_TRIGGER => "trigger",
- PEAR_ERROR_DIE => "die");
+ PEAR_ERROR_DIE => "die",
+ PEAR_ERROR_CALLBACK => "callback");
$levels = array(E_USER_NOTICE => "notice",
E_USER_WARNING => "warning",
E_USER_ERROR => "error");
Index: php4/pear/DB/common.php
diff -u php4/pear/DB/common.php:1.17 php4/pear/DB/common.php:1.18
--- php4/pear/DB/common.php:1.17 Thu Sep 7 09:36:22 2000
+++ php4/pear/DB/common.php Fri Sep 8 19:39:56 2000
@@ -41,6 +41,9 @@
var $prepare_tokens;
var $prepare_types;
var $prepare_maxstmt;
+ var $error_mode = PEAR_ERROR_RETURN;
+ var $error_level = E_USER_NOTICE;
+ var $error_callback;
// }}}
// {{{ toString()
@@ -116,7 +119,7 @@
//php_error(E_WARNING, get_class($this)."::errorCode: no mapping for $nativecode");
// Fall back to DB_ERROR if there was no mapping. Ideally,
// this should never happen.
- return new DB_Error();
+ return $this->raiseError();
}
// }}}
@@ -136,7 +139,61 @@
}
// }}}
+ // {{{ raiseError()
+ function &raiseError($code = DB_ERROR, $mode = false, $level = false) {
+ if (!$mode) {
+ $mode = $this->error_mode;
+ }
+ 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) {
+ $level = $this->error_level;
+ }
+ }
+ return new DB_Error($code, $mode, $level);
+ }
+
+ // }}}
+ // {{{ setErrorHandling()
+
+ function setErrorHandling($mode, $level = false) {
+ switch ($mode) {
+ case PEAR_ERROR_RETURN:
+ case PEAR_ERROR_PRINT:
+ case PEAR_ERROR_TRIGGER:
+ case PEAR_ERROR_DIE:
+ $this->error_mode = $mode;
+ if (!$level) {
+ $this->error_level = E_USER_NOTICE;
+ } else {
+ $this->error_level = $level;
+ }
+ break;
+ case PEAR_ERROR_CALLBACK:
+ $this->error_mode = $mode;
+ if (is_string($level) ||
+ (is_array($level) && sizeof($level) == 2 &&
+ is_object($level[0]) && is_string($level[1]))) {
+ $this->error_callback = $level;
+ } else {
+ trigger_error(E_USER_WARNING, "invalid error callback");
+ }
+ $this->error_level = PEAR_ERROR_RETURN;
+ break;
+ default:
+ trigger_error(E_USER_WARNING, "invalid error mode");
+ break;
+ }
+ }
+
+ // }}}
+
// {{{ prepare()
/**
@@ -177,14 +234,14 @@
if (!isset($this->prepare_tokens[$stmt]) ||
!is_array($this->prepare_tokens[$stmt]) ||
!sizeof($this->prepare_tokens[$stmt])) {
- return new DB_Error(DB_ERROR_INVALID);
+ return $this->raiseError(DB_ERROR_INVALID);
}
$qq = &$this->prepare_tokens[$stmt];
$qp = sizeof($qq) - 1;
if ((!$data && $qp > 0) ||
(!is_array($data) && $qp > 1) ||
(is_array($data) && $qp > sizeof($data))) {
- return new DB_Error(DB_ERROR_NEED_MORE_DATA);
+ return $this->raiseError(DB_ERROR_NEED_MORE_DATA);
}
$realquery = $qq[0];
for ($i = 0; $i < $qp; $i++) {
@@ -413,7 +470,7 @@
}
$cols = $this->numCols($res);
if ($cols < 2) {
- return new DB_Error(DB_ERROR_TRUNCATED);
+ return $this->raiseError(DB_ERROR_TRUNCATED);
}
$results = array();
if ($cols > 2 || $force_array) {
Index: php4/pear/DB/ibase.php
diff -u php4/pear/DB/ibase.php:1.5 php4/pear/DB/ibase.php:1.6
--- php4/pear/DB/ibase.php:1.5 Wed Aug 23 18:34:16 2000
+++ php4/pear/DB/ibase.php Fri Sep 8 19:39:56 2000
@@ -16,7 +16,7 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: ibase.php,v 1.5 2000/08/24 01:34:16 sterling Exp $
+// $Id: ibase.php,v 1.6 2000/09/09 02:39:56 ssb Exp $
//
// Database independent query interface definition for PHP's Interbase
// extension.
@@ -48,7 +48,7 @@
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
- return new DB_Error();
+ return $this->raiseError();
}
$user = $dsninfo['username'];
$pw = $dsninfo['password'];
@@ -61,7 +61,7 @@
} elseif ($dbhost) {
$conn = $connect_function($dbhost);
} else {
- return new DB_Error();
+ return $this->raiseError();
}
$this->connection = $conn;
return DB_OK;
@@ -74,7 +74,7 @@
function &query( $stmt ) {
$result = @ibase_query($this->connection, $stmt);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -89,7 +89,7 @@
function simpleQuery($stmt) {
$result = @ibase_query($this->connection, $stmt);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -103,25 +103,25 @@
$row = ibase_fetch_row($result);
}
if (!$row) {
- return new DB_Error();
+ return $this->raiseError();
}
return $row;
}
function fetchInto($result, &$ar, $getmode=DB_GETMODE_DEFAULT) {
if ($getmode & DB_GETMODE_ASSOC) {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
} else {
$ar = ibase_fetch_row($result);
}
if (!$ar) {
- return new DB_Error();
+ return $this->raiseError();
}
return DB_OK;
}
function freeResult() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
function freeQuery($query) {
@@ -132,7 +132,7 @@
function numCols($result) {
$cols = ibase_num_fields($result);
if (!$cols) {
- return new DB_Error();
+ return $this->raiseError();
}
return $cols;
}
@@ -144,13 +144,13 @@
function execute($stmt, $data = false) {
$result = ibase_execute($stmt, $data);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $stmt) ? $result : DB_OK;
}
function autoCommit($onoff=false) {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
function commit() {
Index: php4/pear/DB/msql.php
diff -u php4/pear/DB/msql.php:1.6 php4/pear/DB/msql.php:1.7
--- php4/pear/DB/msql.php:1.6 Wed Aug 23 18:34:16 2000
+++ php4/pear/DB/msql.php Fri Sep 8 19:39:56 2000
@@ -16,7 +16,7 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: msql.php,v 1.6 2000/08/24 01:34:16 sterling Exp $
+// $Id: msql.php,v 1.7 2000/09/09 02:39:56 ssb Exp $
//
// Database independent query interface definition for PHP's Mini-SQL
// extension.
@@ -48,7 +48,7 @@
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
- return new DB_Error();
+ return $this->raiseError();
}
$user = $dsninfo['username'];
@@ -65,7 +65,7 @@
if ($dsninfo['database']) {
@msql_select_db($dsninfo['database'], $conn);
} else {
- return new DB_Error();
+ return $this->raiseError();
}
$this->connection = $conn;
return DB_OK;
@@ -78,7 +78,7 @@
function &query( $stmt ) {
$result = @msql_query($stmt, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -93,7 +93,7 @@
function simpleQuery($stmt) {
$result = @msql_query($stmt, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -111,7 +111,7 @@
$row = @msql_fetch_row($result);
}
if (!$row) {
- return new DB_Error();
+ return $this->raiseError();
}
return $row;
}
@@ -123,7 +123,7 @@
$ar = @msql_fetch_row($result);
}
if (!$ar) {
- return new DB_Error();
+ return $this->raiseError();
}
return DB_OK;
}
@@ -143,7 +143,7 @@
function numCols($result) {
$cols = @msql_num_fields($result);
if (!$cols) {
- return new DB_Error();
+ return $this->raiseError();
}
return $cols;
}
@@ -173,7 +173,7 @@
$realquery = $this->execute_emulate_query($stmt, $data);
$result = @msql_query($realquery, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
if ( preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $realquery) ) {
return $result;
@@ -183,15 +183,15 @@
}
function autoCommit($onoff=false) {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
function commit() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
function rollback() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
}
Index: php4/pear/DB/mssql.php
diff -u php4/pear/DB/mssql.php:1.9 php4/pear/DB/mssql.php:1.10
--- php4/pear/DB/mssql.php:1.9 Wed Aug 23 18:34:16 2000
+++ php4/pear/DB/mssql.php Fri Sep 8 19:39:56 2000
@@ -16,7 +16,7 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: mssql.php,v 1.9 2000/08/24 01:34:16 sterling Exp $
+// $Id: mssql.php,v 1.10 2000/09/09 02:39:56 ssb Exp $
//
// Database independent query interface definition for PHP's Microsoft SQL Server
// extension.
@@ -48,7 +48,7 @@
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
- return new DB_Error();
+ return $this->raiseError();
}
$user = $dsninfo['username'];
@@ -65,7 +65,7 @@
if ($dsninfo['database']) {
@mssql_select_db($dsninfo['database'], $conn);
} else {
- return new DB_Error();
+ return $this->raiseError();
}
$this->connection = $conn;
return DB_OK;
@@ -78,7 +78,7 @@
function &query( $stmt ) {
$result = @mssql_query($stmt, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -93,7 +93,7 @@
function simpleQuery($stmt) {
$result = @mssql_query($stmt, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -111,7 +111,7 @@
$row = @mssql_fetch_row($result);
}
if (!$row) {
- return new DB_Error();
+ return $this->raiseError();
}
return $row;
}
@@ -123,7 +123,7 @@
$ar = @mssql_fetch_row($result);
}
if (!$ar) {
- return new DB_Error();
+ return $this->raiseError();
}
return DB_OK;
}
@@ -143,7 +143,7 @@
function numCols($result) {
$cols = @mssql_num_fields($result);
if (!$cols) {
- return new DB_Error();
+ return $this->raiseError();
}
return $cols;
}
@@ -173,7 +173,7 @@
$realquery = $this->execute_emulate_query($stmt, $data);
$result = @mssql_query($realquery, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
if ( preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $realquery) ) {
return $result;
@@ -183,15 +183,15 @@
}
function autoCommit($onoff=false) {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
function commit() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
function rollback() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
}
Index: php4/pear/DB/mysql.php
diff -u php4/pear/DB/mysql.php:1.22 php4/pear/DB/mysql.php:1.23
--- php4/pear/DB/mysql.php:1.22 Sun Aug 27 12:46:01 2000
+++ php4/pear/DB/mysql.php Fri Sep 8 19:39:56 2000
@@ -90,7 +90,7 @@
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] :
'localhost';
$user = $dsninfo['username'];
@@ -106,11 +106,11 @@
$conn = false;
}
if ($conn == false) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
if ($dsninfo['database']) {
if (!mysql_select_db($dsninfo['database'], $conn)) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
}
$this->connection = $conn;
@@ -146,9 +146,9 @@
* on failure
*/
function &query($query) {
- $result = mysql_query($query, $this->connection);
+ $result = @mysql_query($query, $this->connection);
if (!$result) {
- return new DB_Error($this->errorCode(mysql_errno($this->connection)));
+ return $this->raiseError($this->errorCode(mysql_errno($this->connection)));
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -178,7 +178,7 @@
function simpleQuery($query) {
$result = mysql_query($query, $this->connection);
if (!$result) {
- return new DB_Error($this->errorCode(mysql_errno($this->connection)));
+ return $this->raiseError($this->errorCode(mysql_errno($this->connection)));
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -214,7 +214,7 @@
if (!$errno) {
return NULL;
}
- return new DB_Error($this->errorCode($errno));
+ return $this->raiseError($this->errorCode($errno));
}
return $row;
}
@@ -244,7 +244,7 @@
if (!$errno) {
return NULL;
}
- return new DB_Error($this->errorCode($errno));
+ return $this->raiseError($this->errorCode($errno));
}
return DB_OK;
}
@@ -288,7 +288,7 @@
function numCols($result) {
$cols = mysql_num_fields($result);
if (!$cols) {
- return new DB_Error($this->errorCode(mysql_errno($this->connection)));
+ return $this->raiseError($this->errorCode(mysql_errno($this->connection)));
}
return $cols;
}
@@ -364,7 +364,7 @@
$realquery = $this->execute_emulate_query($stmt, $data);
$result = mysql_query($realquery, $this->connection);
if (!$result) {
- return new DB_Error($this->errorCode(mysql_errno($this->connection)));
+ return $this->raiseError($this->errorCode(mysql_errno($this->connection)));
}
if (preg_match('/(SELECT|SHOW)/i', $realquery)) {
return $result;
@@ -384,7 +384,7 @@
* @return object DB error code (not capable)
*/
function autoCommit($onoff = false) {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
// }}}
@@ -398,7 +398,7 @@
* @return object DB error code (not capable)
*/
function commit() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
// }}}
@@ -413,7 +413,7 @@
* @return object DB error code (not capable)
*/
function rollback() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
// }}}
Index: php4/pear/DB/oci8.php
diff -u php4/pear/DB/oci8.php:1.6 php4/pear/DB/oci8.php:1.7
--- php4/pear/DB/oci8.php:1.6 Mon Aug 21 07:40:55 2000
+++ php4/pear/DB/oci8.php Fri Sep 8 19:39:56 2000
@@ -75,7 +75,7 @@
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
- return new DB_Error();
+ return $this->raiseError();
}
$user = $dsninfo['username'];
$pw = $dsninfo['password'];
@@ -90,7 +90,7 @@
$conn = false;
}
if ($conn == false) {
- return new DB_Error();
+ return $this->raiseError();
}
$this->connection = $conn;
return DB_OK;
@@ -123,7 +123,7 @@
function &query($query) {
$result = OCIParse($this->connection, $query);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
if ($this->autoCommit) {
$success=OCIExecute($result,OCI_COMMIT_ON_SUCCESS);
@@ -132,7 +132,7 @@
$success=OCIExecute($result,OCI_DEFAULT);
}
if (!$success) {
- return new DB_Error();
+ return $this->raiseError();
}
$this->last_stmt=$result;
// Determine which queries that should return data, and which
@@ -161,7 +161,7 @@
function simpleQuery($query) {
$result = OCIParse($this->connection, $query);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
if ($this->autoCommit) {
$success=OCIExecute($result,OCI_COMMIT_ON_SUCCESS);
@@ -170,7 +170,7 @@
$success=OCIExecute($result,OCI_DEFAULT);
}
if (!$success) {
- return new DB_Error();
+ return $this->raiseError();
}
$this->last_stmt=$result;
// Determine which queries that should return data, and which
@@ -201,7 +201,7 @@
$moredata=OCIFetchInto($result,$row,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
}
if (!$row) {
- return new DB_Error();
+ return $this->raiseError();
}
if ($moredata==NULL) {
return NULL;
@@ -228,7 +228,7 @@
$moredata=OCIFetchInto($result,$arr,OCI_RETURN_NULLS+OCI_RETURN_LOBS);
}
if (!($arr && $moredata)) {
- return new DB_Error();
+ return $this->raiseError();
}
return DB_OK;
}
@@ -268,7 +268,7 @@
function numCols($result) {
$cols = OCINumCols($result);
if (!$cols) {
- return new DB_Error();
+ return $this->raiseError();
}
return $cols;
}
@@ -343,7 +343,7 @@
function execute($stmt, $data = false) {
$types=&$this->prepare_types[$stmt];
if (($size=sizeof($types))!=sizeof($data)) {
- return new DB_Error();
+ return $this->raiseError();
}
for ($i=0;$i<$size;$i++) {
if (is_array($data)) {
@@ -362,7 +362,7 @@
}
}
if (!OCIBindByName($stmt,":bind".$i,$pdata[$i],-1)) {
- return new DB_Error();
+ return $this->raiseError();
}
}
if ($this->autoCommit) {
@@ -372,7 +372,7 @@
$success=OCIExecute($stmt,OCI_DEFAULT);
}
if (!$success) {
- return new DB_Error();
+ return $this->raiseError();
}
$this->last_stmt=$stmt;
if ($this->select_query[$stmt]) {
@@ -412,7 +412,7 @@
function commit() {
$result = OCICommit($this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
return DB_OK;
}
@@ -428,7 +428,7 @@
function rollback() {
$result = OCIRollback($this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
return DB_OK;
}
@@ -444,11 +444,11 @@
*/
function affectedRows() {
if ($this->last_stmt === false) {
- return new DB_Error();
+ return $this->raiseError();
}
$result = OCIRowCount($this->last_stmt);
if ($result === false) {
- return new DB_Error();
+ return $this->raiseError();
}
return $result;
}
Index: php4/pear/DB/odbc.php
diff -u php4/pear/DB/odbc.php:1.13 php4/pear/DB/odbc.php:1.14
--- php4/pear/DB/odbc.php:1.13 Wed Aug 23 19:26:38 2000
+++ php4/pear/DB/odbc.php Fri Sep 8 19:39:56 2000
@@ -100,7 +100,7 @@
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
$this->dbsyntax = $dsninfo['dbsyntax'];
switch ($this->dbsyntax) {
@@ -133,7 +133,7 @@
$conn = false;
}
if ($conn == false) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
$this->connection = $conn;
return DB_OK;
@@ -157,7 +157,7 @@
function query($query) {
$result = odbc_exec($this->connection, $query);
if (!$result) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -185,7 +185,7 @@
function simpleQuery($query) {
$result = odbc_exec($this->connection, $query);
if (!$result) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
// Determine which queries that should return data, and which
// should return an error code only.
Index: php4/pear/DB/pgsql.php
diff -u php4/pear/DB/pgsql.php:1.10 php4/pear/DB/pgsql.php:1.11
--- php4/pear/DB/pgsql.php:1.10 Mon Aug 21 07:40:55 2000
+++ php4/pear/DB/pgsql.php Fri Sep 8 19:39:56 2000
@@ -95,7 +95,7 @@
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] :
'localhost';
$user = $dsninfo['username'];
@@ -117,7 +117,7 @@
$conn = false;
}
if ($conn == false) {
- return new DB_Error(); // XXX ERRORMSG
+ return $this->raiseError(); // XXX ERRORMSG
}
$this->connection = $conn;
return DB_OK;
@@ -255,7 +255,7 @@
return $errno;
*/
// the error codes are not supported in pgsql.
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
$this->row[$result]++;
return DB_OK;
@@ -333,7 +333,7 @@
function errorNative() {
/* return pg_errormessage($this->connection); */
// the error codes are not supported in pgsql.
- return new DB_Error();
+ return $this->raiseError();
}
// }}}
@@ -394,7 +394,7 @@
* Enable/disable automatic commits [not supported by PostgreSQL]
*/
function autoCommit($onoff = false) {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
// }}}
Index: php4/pear/DB/sybase.php
diff -u php4/pear/DB/sybase.php:1.5 php4/pear/DB/sybase.php:1.6
--- php4/pear/DB/sybase.php:1.5 Wed Aug 23 18:34:16 2000
+++ php4/pear/DB/sybase.php Fri Sep 8 19:39:56 2000
@@ -16,7 +16,7 @@
// | Authors: Sterling Hughes <sterling@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: sybase.php,v 1.5 2000/08/24 01:34:16 sterling Exp $
+// $Id: sybase.php,v 1.6 2000/09/09 02:39:56 ssb Exp $
//
// Database independent query interface definition for PHP's Sybase
// extension.
@@ -48,7 +48,7 @@
$dsninfo = DB::parseDSN($dsn);
}
if (!$dsninfo || !$dsninfo['phptype']) {
- return new DB_Error();
+ return $this->raiseError();
}
$dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] :
'localhost';
$connect_function = $persistent ? 'sybase_pconnect' : 'sybase_connect';
@@ -65,7 +65,7 @@
function &query( $stmt ) {
$result = @sybase_query($stmt, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -80,7 +80,7 @@
function simpleQuery($stmt) {
$result = @sybase_query($stmt, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
// Determine which queries that should return data, and which
// should return an error code only.
@@ -90,7 +90,7 @@
function &fetchRow($result, $getmode=DB_GETMODE_DEFAULT) {
$row = ($getmode & DB_GETMODE_ASSOC) ? @sybase_fetch_array($result) :
@sybase_fetch_row($result);
if (!$row) {
- return new DB_Error();
+ return $this->raiseError();
}
return $row;
}
@@ -98,7 +98,7 @@
function fetchInto($result, &$ar, $getmode=DB_GETMODE_DEFAULT) {
$ar = ($getmode & DB_GETMODE_ASSOC) ? @sybase_fetch_array($result) :
@sybase_fetch_row($result);
if (!$ar) {
- return new DB_Error();
+ return $this->raiseError();
}
return DB_OK;
}
@@ -118,7 +118,7 @@
function numCols($result) {
$cols = @sybase_num_fields($result);
if (!$cols) {
- return new DB_Error();
+ return $this->raiseError();
}
return $cols;
}
@@ -148,21 +148,21 @@
$realquery = $this->execute_emulate_query($stmt, $data);
$result = @sybase_query($realquery, $this->connection);
if (!$result) {
- return new DB_Error();
+ return $this->raiseError();
}
return preg_match('/(SELECT|SHOW|LIST|DESCRIBE)/i', $realquery) ? $result : DB_OK;
}
function autoCommit($onoff=false) {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
function commit() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
function rollback() {
- return new DB_Error(DB_ERROR_NOT_CAPABLE);
+ return $this->raiseError(DB_ERROR_NOT_CAPABLE);
}
}
?>
Index: php4/pear/DB/.cvsignore
+++ php4/pear/DB/.cvsignore
TAGS
Index: php4/pear/DB/tests/db_error.phpt
+++ php4/pear/DB/tests/db_error.phpt
--TEST--
DB_Error/DB_Warning test
--SKIPIF--
<?php if (!include("DB.php")) print "skip"; ?>
--FILE--
<?php // -*- C++ -*-
// Test for: DB.php
// Parts tested: DB_Error, DB_Warning
require_once "DB.php";
print "testing different error codes...\n";
$e = new DB_Error(); print $e->toString()."\n";
$e = new DB_Error("test error"); print $e->toString()."\n";
$e = new DB_Error(DB_OK); print $e->toString()."\n";
$e = new DB_Error(DB_ERROR); print $e->toString()."\n";
$e = new DB_Error(DB_ERROR_SYNTAX); print $e->toString()."\n";
$e = new DB_Error(DB_ERROR_DIVZERO); print $e->toString()."\n";
$e = new DB_Warning(); print $e->toString()."\n";
$e = new DB_Warning("test warning"); print $e->toString()."\n";
$e = new DB_Warning(DB_WARNING_READ_ONLY); print $e->toString()."\n";
print "testing different error modes...\n";
$e = new DB_Error(DB_ERROR, PEAR_ERROR_PRINT); print $e->toString()."\n";
$e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER);
print "testing different error serverities...\n";
$e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER, E_USER_NOTICE);
$e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER, E_USER_WARNING);
$e = new DB_Error(DB_ERROR_SYNTAX, PEAR_ERROR_TRIGGER, E_USER_ERROR);
?>
--GET--
--POST--
--EXPECT--
testing different error codes...
[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice
prefix="" prepend="" append=""]
[db_error: message="DB Error: test error" code=0 mode=return level=notice
prefix="" prepend="" append=""]
[db_error: message="DB Error: no error" code=0 mode=return level=notice
prefix="" prepend="" append=""]
[db_error: message="DB Error: unknown error" code=-1 mode=return level=notice
prefix="" prepend="" append=""]
[db_error: message="DB Error: syntax error" code=-2 mode=return level=notice
prefix="" prepend="" append=""]
[db_error: message="DB Error: division by zero" code=-13 mode=return level=notice
prefix="" prepend="" append=""]
[db_warning: message="DB Warning: unknown warning" code=-1000 mode=return level=notice
prefix="" prepend="" append=""]
[db_warning: message="DB Warning: test warning" code=0 mode=return level=notice
prefix="" prepend="" append=""]
[db_warning: message="DB Warning: read only" code=-1001 mode=return level=notice
prefix="" prepend="" append=""]
testing different error modes...
DB Error: unknown error[db_error: message="DB Error: unknown error" code=-1 mode=print
level=notice prefix="" prepend="" append=""]
<br>
<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line
<b>198</b><br>
testing different error serverities...
<br>
<b>Notice</b>: DB Error: syntax error in <b>PEAR.php</b> on line
<b>198</b><br>
<br>
<b>Warning</b>: DB Error: syntax error in <b>PEAR.php</b> on line
<b>198</b><br>
<br>
<b>Fatal error</b>: DB Error: syntax error in <b>PEAR.php</b> on line
<b>198</b><br>
Index: php4/pear/DB/tests/db_error2.phpt
+++ php4/pear/DB/tests/db_error2.phpt
--TEST--
DB configurable error handler test
--FILE--
<?php
require_once "DB.php";
error_reporting(4095);
function myfunc(&$obj) {
print "myfunc here, obj=".$obj->toString()."\n";
}
class myclass {
function myfunc(&$obj) {
print "myclass::myfunc here, obj=".$obj->toString()."\n";
}
}
$obj = new myclass;
$dbh = DB::factory("mysql");
print "default: ";
$e = $dbh->raiseError("return testing error");
print $e->toString() . "\n";
$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=0 mode=return
level=notice prefix="" prepend="" append=""]
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>198</b><br>
mode=function callback: myfunc here, obj=[db_error: message="DB Error: function callback
testing error" code=0 mode=callback level=notice prefix="" prepend=""
append=""]
mode=object callback: myclass::myfunc here, obj=[db_error: message="DB Error: object callback
testing error" code=0 mode=callback level=notice prefix="" prepend=""
append=""]
Index: php4/pear/DB/tests/db_factory.phpt
+++ php4/pear/DB/tests/db_factory.phpt
--TEST--
DB::factory test
--SKIPIF--
<?php if (!include("DB.php")) print "skip"; ?>
--FILE--
<?php // -*- C++ -*-
// Test for: DB.php
// Parts tested: DB_Error, DB_Warning
require_once "DB.php";
$backends = array(
"ibase",
"msql",
"mssql",
"mysql",
"oci8",
"odbc",
"pgsql",
"sybase"
);
reset($backends);
while (list($i, $name) = each($backends)) {
print "testing $name: ";
$obj = DB::factory($name);
if (DB::isError($obj)) {
print "error: ".$obj->getMessage()."\n";
} else {
print "object: ".$obj->toString()."\n";
}
}
?>
--GET--
--POST--
--EXPECT--
testing ibase: object: db_ibase: (phptype=ibase, dbsyntax=ibase)
testing msql: object: db_msql: (phptype=msql, dbsyntax=msql)
testing mssql: object: db_mssql: (phptype=mssql, dbsyntax=mssql)
testing mysql: object: db_mysql: (phptype=mysql, dbsyntax=mysql)
testing oci8: object: db_oci8: (phptype=oci8, dbsyntax=oci8)
testing odbc: object: db_odbc: (phptype=odbc, dbsyntax=unknown)
testing pgsql: object: db_pgsql: (phptype=pgsql, dbsyntax=pgsql)
testing sybase: object: db_sybase: (phptype=sybase, dbsyntax=sybase)
Index: php4/pear/DB/tests/db_parsedsn.phpt
+++ php4/pear/DB/tests/db_parsedsn.phpt
--TEST--
DB::parseDSN test
--SKIPIF--
<?php if (!include("DB.php")) print "skip"; ?>
--FILE--
<?php // -*- C++ -*-
// Test for: DB.php
// Parts tested: DB_Error, DB_Warning
require_once "DB.php";
function test($dsn) {
print implode(",", DB::parseDSN($dsn))."\n";
}
print "testing DB::parseDSN...\n";
test("mysql");
test("odbc(mssql)");
test("mysql://localhost");
test("mysql://remote.host.com/db");
test("mysql://testuser:testpw");
test("oci8://user:pass@tns-name");
test("odbc(solid)://foo:bar@tcp+localhost+1313");
/* phptype,dbsyntax,protocol,hostspec,database,username,password */
?>
--GET--
--POST--
--EXPECT--
testing DB::parseDSN...
mysql,,,,,,
odbc,mssql,,,,,
mysql,mysql,,localhost,,,
mysql,mysql,,remote.host.com,db,,
mysql,mysql,,,,testuser,testpw
oci8,oci8,,tns-name,,user,pass
odbc,solid,tcp,localhost 1313,,foo,bar
Index: php4/pear/tests/pear1.phpt
+++ php4/pear/tests/pear1.phpt
--TEST--
PEAR constructor/destructor test
--SKIPIF--
--FILE--
<?php
require_once "PEAR.php";
class TestPEAR extends PEAR {
function TestPEAR($name) {
$this->_debug = true;
$this->name = $name;
$this->PEAR();
}
function _TestPEAR() {
print "This is the TestPEAR($this->name) destructor\n";
$this->_PEAR();
}
}
print "test class TestPEAR\n";
$o = new TestPEAR("test1");
$p = new TestPEAR("test2");
var_dump(get_class($o));
var_dump(get_class($p));
?>
--GET--
--POST--
--EXPECT--
test class TestPEAR
PEAR constructor called, class=testpear
PEAR constructor called, class=testpear
string(8) "testpear"
string(8) "testpear"
This is the TestPEAR(test1) destructor
PEAR destructor called, class=testpear
This is the TestPEAR(test2) destructor
PEAR destructor called, class=testpear
Index: php4/pear/tests/pear_error.phpt
+++ php4/pear/tests/pear_error.phpt
--TEST--
PEAR_Error test
--SKIPIF--
--FILE--
<?php // -*- C++ -*-
// Test for: PEAR.php
// Parts tested: - PEAR_Error class
// - PEAR::isError static method
// testing PEAR_Error
require_once "PEAR.php";
error_reporting(4095);
print "default PEAR_Error: ";
$err = new PEAR_Error;
print $err->toString() . "\n";
print "Testing it: ";
var_dump(PEAR::isError($err));
print "This is not an error: ";
$str = "not an error";
var_dump(PEAR::isError($str));
print "Now trying a bunch of variations...\n";
print "different message: ";
$err = new PEAR_Error("test error");
print $err->toString() . "\n";
print "different message,code: ";
$err = new PEAR_Error("test error", -42);
print $err->toString() . "\n";
print "mode=print: ";
$err = new PEAR_Error("test error", -42, PEAR_ERROR_PRINT);
print $err->toString() . "\n";
print "mode=trigger: ";
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER);
print $err->toString() . "\n";
print "mode=trigger,level=notice: ";
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_NOTICE);
print $err->toString() . "\n";
print "mode=trigger,level=warning: ";
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_WARNING);
print $err->toString() . "\n";
print "mode=trigger,level=error: ";
$err = new PEAR_Error("test error", -42, PEAR_ERROR_TRIGGER, E_USER_ERROR);
print $err->toString() . "\n";
?>
--GET--
--POST--
--EXPECT--
default PEAR_Error: [pear_error: message="unknown error" code=0 mode=return level=notice
prefix="" prepend="" append=""]
Testing it: bool(true)
This is not an error: bool(false)
Now trying a bunch of variations...
different message: [pear_error: message="test error" code=0 mode=return level=notice
prefix="" prepend="" append=""]
different message,code: [pear_error: message="test error" code=-42 mode=return
level=notice prefix="" prepend="" append=""]
mode=print: test error[pear_error: message="test error" code=-42 mode=print level=notice
prefix="" prepend="" append=""]
mode=trigger: <br>
<b>Notice</b>: test error in <b>PEAR.php</b> on line
<b>198</b><br>
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix=""
prepend="" append=""]
mode=trigger,level=notice: <br>
<b>Notice</b>: test error in <b>PEAR.php</b> on line
<b>198</b><br>
[pear_error: message="test error" code=-42 mode=trigger level=notice prefix=""
prepend="" append=""]
mode=trigger,level=warning: <br>
<b>Warning</b>: test error in <b>PEAR.php</b> on line
<b>198</b><br>
[pear_error: message="test error" code=-42 mode=trigger level=warning prefix=""
prepend="" append=""]
mode=trigger,level=error: <br>
<b>Fatal error</b>: test error in <b>PEAR.php</b> on line
<b>198</b><br>
Index: php4/pear/tests/pear_error2.phpt
+++ php4/pear/tests/pear_error2.phpt
--TEST--
PEAR_Error in die mode
--SKIPIF--
--FILE--
<?php // -*- C++ -*-
// Test for: PEAR.php
// Parts tested: - PEAR_Error class
// - PEAR::isError static method
// testing PEAR_Error
require_once "PEAR.php";
error_reporting(4095);
print "mode=die: ";
$err = new PEAR_Error("test error!!\n", -42, PEAR_ERROR_DIE);
print $err->toString() . "\n";
?>
--GET--
--POST--
--EXPECT--
mode=die: test error!!
Index: php4/pear/tests/pear_error_callback.phpt
+++ php4/pear/tests/pear_error_callback.phpt
--TEST--
PEAR_Error in callback mode
--SKIPIF--
--FILE--
<?php
require_once "PEAR.php";
function error_function($obj) {
print "this is error_function reporting: ";
print $obj->toString();
print "\n";
}
class myclass {
function error_method($obj) {
print "this is myclass::error_method reporting: ";
print $obj->toString();
print "\n";
}
}
$obj = new myclass;
new PEAR_Error("errortest1", 0, PEAR_ERROR_CALLBACK, "error_function");
new PEAR_Error("errortest2", 0, PEAR_ERROR_CALLBACK,
array(&$obj, "error_method"));
?>
--GET--
--POST--
--EXPECT--
this is error_function reporting: [pear_error: message="errortest1" code=0 mode=callback
level=notice prefix="" prepend="" append=""]
this is myclass::error_method reporting: [pear_error: message="errortest2" code=0
mode=callback level=notice prefix="" prepend="" append=""]