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:

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:

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.

Comments

Posted by Salvador Ledezma (ledezma) on 2007-07-11T20:22:13.000+0000

Contains modified errorCode() and errorInfo() methods

Posted by Salvador Ledezma (ledezma) on 2007-07-11T20:23:33.000+0000

removed skipped error tests

Posted by Darby Felton (darby) on 2007-11-13T12:52:39.000+0000

Assigning to [~ledezma]

Posted by Thomas Weidner (thomas) on 2008-03-12T14:45:21.000+0000

Hy Salvador,

if you are not able to commit this patch, you should un-assign this issue so anyone with commit-rights will do this.

Otherwise please commit your changes and close this issue. ;-)

Posted by Salvador Ledezma (ledezma) on 2008-03-12T18:00:48.000+0000

I had submitted these patches for review by someone with commit authority.

Please use as you see fit.

Posted by Wil Sinclair (wil) on 2008-03-25T22:02:49.000+0000

Resetting 'fix version priority' and 'fix version' to be re-evaluated for next release.

Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2008-12-07T20:53:30.000+0000

Solved in SVN r 13091.
If no error occurs, errorCode() and errorInfo() method returns false like Oracle and MySqli.

Posted by Ralph Schindler (ralph) on 2008-12-15T11:53:55.000+0000

Unit test not updated to reflect changes.

Posted by Ralph Schindler (ralph) on 2008-12-15T12:08:47.000+0000

fixed in r13279, still needs merging - will do so close to next mini release.

Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2009-01-19T07:38:47.000+0000