zendframework/zend-db

no error code for statement runtime exception

Opened this issue · 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.

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 ?

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 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?)

This repository has been closed and moved to laminas/laminas-db; a new issue has been opened at laminas/laminas-db#75.