Details
-
Type:
Patch
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.0.0
-
Fix Version/s: 1.7.3
-
Component/s: Zend_Db_Adapter_Db2
-
Labels:None
-
Fix Version Priority:Should Have
Description
Calling db2_stmt_error() or db2_stmt_errormsg() without a statement resource parameter will also return the error message from the last operation, if there is one. This message is cached so no matter how many times it is called and as long as another SQL operation doesn't occur, it will return the same message
If either function is called with a statement resource, it will return the message associated with that particular resource. A subsequent call with the same resource parameter attempts to retrieve further diagnostic data. If there is no more diagnostic data, nothing is returned.
In the ZF, a particular method, such as execute(), may throw an exception. The exception object is populated with specific diagnostic information using db2_stmt_error() and db2_stmt_erromsg(). For example, this is what _execute() looks like for the DB2 adapter:
if ($retval === false) { /** * @see Zend_Db_Statement_Db2_Exception */ require_once 'Zend/Db/Statement/Db2/Exception.php'; throw new Zend_Db_Statement_Db2_Exception( db2_stmt_errormsg($this->_stmt), db2_stmt_error($this->_stmt)); }
When an application detects an exception it may try to call errorCode() or errorInfo(). The problem is that both these methods call db2_stmt_error() with the $this->_stmt instance variable again.
For example:
public function errorCode() { if (!$this->_stmt) { return '0000'; } return db2_stmt_error($this->_stmt); }
Since db2_stmt_error($this->_stmt) has been previously called when the exception was generated, the driver attempts to obtain further diagnostic data. If there is none, nothing is returned giving the impression that there is no error message.
The patch removes the $this->_stmt parameter from the errorCode() and errorInfo() methods so that repeated calls to db_stmt_error() and db2_stmt_errormsg() return the same message previously cached.
I will upload the patch as well as the modified DB2 unit test.
Attachments
Issue Links
| This issue is related to: | ||||
| ZF-3072 | Support for DB2 on i5 |
|
|
|
Contains modified errorCode() and errorInfo() methods