laminas/laminas-db

no error code for statement runtime exception

Closed 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.


Originally posted by @brettmc at zendframework/zend-db#243

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 ?


Originally posted by @brettmc at zendframework/zend-db#243 (comment)

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

Originally posted by @chukShirley at zendframework/zend-db#243 (comment)

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


Originally posted by @brettmc at zendframework/zend-db#243 (comment)

This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering Committee.
If you have a security issue, please follow our security reporting guidelines.
If you wish to take on the role of maintainer, please nominate yourself

If you are looking for an actively maintained package alternative, we recommend: