zend-db icon indicating copy to clipboard operation
zend-db copied to clipboard

no error code for statement runtime exception

Open brettmc opened this issue 7 years ago • 4 comments

Using Zend\Db\Adapter\Driver\Oci8\Statement as an example, if a runtime error occurs during sql execution (eg duplicate value on insert), the exception's code is populated with a DMBS error code.

Is there any reason not to return a DBMS error code for other drivers (I'm looking at mysqli & pdo)? They are well-defined, and give developers a way of handling different types of runtime exceptions.

brettmc avatar Apr 13 '17 07:04 brettmc

I've started playing with this, and success has been dependent on how DBMS vendors represent exception codes. For example, postgres uses the sql standard SQLSTATE error codes which are non-numeric, so they don't play well with zend-db's exceptions. I see that \PDOException implements string-based error codes (I assume for this very reason). Does it sound palatable to make exception error codes strings in zend-db ?

brettmc avatar Apr 19 '17 12:04 brettmc

I've been experiencing the same thing with the IbmDb2 adapter using PHP 7.1. db2_stmt_error() returns a string, and Zend\Db\Adapter\Exception expects the second constructor parameter to be an integer. When the second parameter is a string, I get

Wrong parameters for Zend\Db\Adapter\Exception\RuntimeException([string $message [, long $code [, Throwable $previous = NULL]]])

chukShirley avatar Apr 20 '17 10:04 chukShirley

@chukShirley I could probably write a failing integration test for that to demonstrate a current bug. Can you provide a simple query which would cause a non-integer error code from DB2? (would something like "select * from non_existent_table" do it?)

brettmc avatar May 05 '17 04:05 brettmc

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at https://github.com/laminas/laminas-db/issues/75.

michalbundyra avatar Jan 16 '20 19:01 michalbundyra