Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.11.5

Bug #473 A DB_Error isn't a DB_Error in function _query()
Submitted: 2003-12-21 22:12 UTC
From: rene dot oelke at zehn245 dot net Assigned: alan_k
Status: Closed Package: DB_DataObject
PHP Version: 4.3.3 OS: SuSE Linux 7.1
Roadmaps: (Not assigned)    
Subscription  


 [2003-12-21 22:12 UTC] rene dot oelke at zehn245 dot net
Description: ------------ A table with the following properties: CREATE TABLE users ( id int(16) unsigned NOT NULL auto_increment, login varchar(255) default NULL, passwd varchar(255) default NULL, name varchar(255) default NULL, sname varchar(255) default NULL, regdate datetime default NULL, email varchar(255) default NULL, lang varchar(255) default NULL, apikey varchar(255) default NULL, PRIMARY KEY (id), UNIQUE KEY login (login), KEY usr_id (id) ) TYPE=MyISAM; A class with the following properties: class MyClass extends DB_DataObject { function DataObjects_Seos_users() { PEAR::setErrorHandling( PEAR_ERROR_CALLBACK, array( &$this, 'handleError' ) ); } ... function handleError( $error ) { if( DB::isError($error) ) echo "<br>Error is DB_Error<br>"; echo "class: " . get_class( $error ) . " type: " . $error->getType() . " code: " . $error->getCode() . " message: " . $error->getMessage() . "<br>"; } } If i update or insert a new row with an existing login-name, the system throws an error. This error is a DB_Error with the code -5. But in the handleError-function i can't check the error as an DB_Error. It is an PEAR_Error. The reason for this "bug" is to find in the DataObject-class in the function _query. Here at line 1627 the query result is checked as an DB_Error. If so the DB_DataObject raises an error (PEAR_Error): ... return DB_DataError::raiseError(...); ... I think this is wrong. An DB_Error should be an DB_Error. I can't exactly ckeck the error code because the DB_DataObject has also an error code -5. So i can't make a correct message for the user-interface. The following code should solve the problem. return DB_DataError::raiseError(..., 'DB_Error'); The type will be tested in raiseError() and here we should raise the PEAR_Error with the correct type (line 2655): $error = PEAR::raiseError($message, $type, $behaviour, null, null, $type, true ); Reproduce code: --------------- function handleError( $error ) { if( DB::isError($error) ) echo "<br>Error is DB_Error<br>"; else echo "<br>Error is no DB_Error<br>"; echo "class: " . get_class( $error ) . " type: " . $error->getType() . " code: " . $error->getCode() . " message: " . $error->getMessage() . "<br>"; } ... INSERT INTO users (login , passwd , name , sname , regdate , email , lang , apikey ) VALUES ('test' , 'password' , 'name' , 'sname' , '2003-12-21 18:57:25' , 'name@email.de' , '' , '' ) INSERT INTO users (login , passwd , name , sname , regdate , email , lang , apikey ) VALUES ('test' , 'password2' , 'name2' , 'sname2' , '2003-12-21 18:59:45' , 'name2@email.com' , '' , '' ) Expected result: ---------------- Error is DB_Error class: db_error type: db_error code: -5 Message: DB Error: already exists ERROR: DB Error: already exists ERROR: Object Actual result: -------------- Error is no DB_Error class: pear_error type: pear_error Code: -5 message: DB Error: already exists ERROR: DB Error: already exists ERROR: Object

Comments

 [2004-01-01 02:49 UTC] alan_k
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. thanks - changed it to return $result (eg. the error) Regards Alan