ZF-1710: DB2: Improved error reporting from errorCode() and errorInfo() methods in Statement class

Issue Type: Patch Created: 2007-07-11T20:16:22.000+0000 Last Updated: 2009-01-19T07:38:55.000+0000 Status: Closed Fix version(s): - 1.7.3 (19/Jan/09)

Reporter: Salvador Ledezma (ledezma) Assignee: old of Satoru Yoshida ( Tags: - Zend_Db_Adapter_Db2

Related issues: - ZF-3072

Attachments: - Db2.php


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:

<pre class="highlight">
if ($retval === false) {
    * @see Zend_Db_Statement_Db2_Exception
   require_once 'Zend/Db/Statement/Db2/Exception.php';
         throw new Zend_Db_Statement_Db2_Exception(

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:

<pre class="highlight">
   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.


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 ( 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 ( on 2009-01-19T07:38:47.000+0000

I checked to be merged from trunk to branch/release-1.7.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.