Zend Framework

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

Details

  • Type: Patch Patch
  • Status: Closed Closed
  • Priority: Minor 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.

  1. Db2.php
    11/Jul/07 8:22 PM
    10 kB
    Salvador Ledezma
  2. Db2Test.php
    11/Jul/07 8:23 PM
    4 kB
    Salvador Ledezma

Issue Links

Activity

Hide
Salvador Ledezma added a comment -

Contains modified errorCode() and errorInfo() methods

Show
Salvador Ledezma added a comment - Contains modified errorCode() and errorInfo() methods
Hide
Salvador Ledezma added a comment -

removed skipped error tests

Show
Salvador Ledezma added a comment - removed skipped error tests
Hide
Darby Felton added a comment -

Assigning to Salvador Ledezma

Show
Darby Felton added a comment - Assigning to Salvador Ledezma
Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.
Hide
Salvador Ledezma added a comment -

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

Please use as you see fit.

Show
Salvador Ledezma added a comment - I had submitted these patches for review by someone with commit authority. Please use as you see fit.
Hide
Wil Sinclair added a comment -

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

Show
Wil Sinclair added a comment - Resetting 'fix version priority' and 'fix version' to be re-evaluated for next release.
Hide
Satoru Yoshida added a comment -

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

Show
Satoru Yoshida added a comment - Solved in SVN r 13091. If no error occurs, errorCode() and errorInfo() method returns false like Oracle and MySqli.
Hide
Ralph Schindler added a comment -

Unit test not updated to reflect changes.

Show
Ralph Schindler added a comment - Unit test not updated to reflect changes.
Hide
Ralph Schindler added a comment -

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

Show
Ralph Schindler added a comment - fixed in r13279, still needs merging - will do so close to next mini release.
Hide
Satoru Yoshida added a comment -

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

Show
Satoru Yoshida added a comment - I checked to be merged from trunk to branch/release-1.7.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
1d
Original Estimate - 1 day
Remaining:
22h 50m
Time Spent - 1 hour, 10 minutes Remaining Estimate - 22 hours, 50 minutes
Logged:
1h 10m
Time Spent - 1 hour, 10 minutes Remaining Estimate - 22 hours, 50 minutes