ID: 50728 Updated by: j...@php.net Reported By: j...@php.net Status: Open Bug Type: PDO related Operating System: All PHP Version: 5.3.2RC1 New Comment:
Patch for HEAD (previous was for tip of 5.3.2 [svn 292727]): Index: ext/pdo_oci/oci_driver.c =================================================================== --- ext/pdo_oci/oci_driver.c (revision 293440) +++ ext/pdo_oci/oci_driver.c (working copy) @@ -173,7 +173,7 @@ /* little mini hack so that we can use this code from the dbh ctor */ if (!dbh->methods) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s]: %s", *pdo_err, einfo->errmsg); + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s]: %s", *pdo_err, einfo->errmsg); } return einfo->errcode; Index: ext/pdo_dblib/dblib_driver.c =================================================================== --- ext/pdo_dblib/dblib_driver.c (revision 293440) +++ ext/pdo_dblib/dblib_driver.c (working copy) @@ -255,7 +255,7 @@ dbh->driver_data = H; if (!ret) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, + zend_throw_exception_ex(php_pdo_get_exception(), DBLIB_G(err).dberr TSRMLS_CC, "SQLSTATE[%s] %s (severity %d)", DBLIB_G(err).sqlstate, DBLIB_G(err).dberrstr, Index: ext/pdo_sqlite/sqlite_driver.c =================================================================== --- ext/pdo_sqlite/sqlite_driver.c (revision 293440) +++ ext/pdo_sqlite/sqlite_driver.c (working copy) @@ -102,7 +102,7 @@ } if (!dbh->methods) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } Index: ext/pdo_mysql/mysql_driver.c =================================================================== --- ext/pdo_mysql/mysql_driver.c (revision 293440) +++ ext/pdo_mysql/mysql_driver.c (working copy) @@ -127,7 +127,7 @@ if (!dbh->methods) { PDO_DBG_INF("Throwing exception"); - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } Index: ext/pdo_firebird/firebird_driver.c =================================================================== --- ext/pdo_firebird/firebird_driver.c (revision 293440) +++ ext/pdo_firebird/firebird_driver.c (working copy) @@ -686,7 +686,7 @@ char errmsg[512]; ISC_STATUS *s = H->isc_status; isc_interprete(errmsg, &s); - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), H->isc_status[1] TSRMLS_CC, "SQLSTATE[%s] [%d] %s", "HY000", H->isc_status[1], errmsg); } Index: ext/pdo_pgsql/pgsql_driver.c =================================================================== --- ext/pdo_pgsql/pgsql_driver.c (revision 293440) +++ ext/pdo_pgsql/pgsql_driver.c (working copy) @@ -87,7 +87,7 @@ } if (!dbh->methods) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } Index: ext/pdo_odbc/odbc_driver.c =================================================================== --- ext/pdo_odbc/odbc_driver.c (revision 293440) +++ ext/pdo_odbc/odbc_driver.c (working copy) @@ -88,10 +88,10 @@ /* printf("@@ SQLSTATE[%s] %s\n", *pdo_err, einfo->last_err_msg); */ if (!dbh->methods) { #if PHP_VERSION_ID > 50200 - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] %s: %d %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->last_error TSRMLS_CC, "SQLSTATE[%s] %s: %d %s", *pdo_err, what, einfo->last_error, einfo->last_err_msg); #else - zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), 0 TSRMLS_CC, "SQLSTATE[%s] %s: %d %s", + zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), einfo->last_error TSRMLS_CC, "SQLSTATE[%s] %s: %d %s", *pdo_err, what, einfo->last_error, einfo->last_err_msg); #endif } Previous Comments: ------------------------------------------------------------------------ [2010-01-12 03:37:41] j...@php.net Index: ext/pdo_oci/oci_driver.c =================================================================== --- ext/pdo_oci/oci_driver.c (revision 292727) +++ ext/pdo_oci/oci_driver.c (working copy) @@ -173,7 +173,7 @@ /* little mini hack so that we can use this code from the dbh ctor */ if (!dbh->methods) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s]: %s", *pdo_err, einfo->errmsg); + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s]: %s", *pdo_err, einfo->errmsg); } return einfo->errcode; Index: ext/pdo_dblib/dblib_driver.c =================================================================== --- ext/pdo_dblib/dblib_driver.c (revision 292727) +++ ext/pdo_dblib/dblib_driver.c (working copy) @@ -255,7 +255,7 @@ dbh->driver_data = H; if (!ret) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, + zend_throw_exception_ex(php_pdo_get_exception(), DBLIB_G(err).dberr TSRMLS_CC, "SQLSTATE[%s] %s (severity %d)", DBLIB_G(err).sqlstate, DBLIB_G(err).dberrstr, Index: ext/pdo_sqlite/sqlite_driver.c =================================================================== --- ext/pdo_sqlite/sqlite_driver.c (revision 292727) +++ ext/pdo_sqlite/sqlite_driver.c (working copy) @@ -78,7 +78,7 @@ } if (!dbh->methods) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } Index: ext/pdo_mysql/mysql_driver.c =================================================================== --- ext/pdo_mysql/mysql_driver.c (revision 292727) +++ ext/pdo_mysql/mysql_driver.c (working copy) @@ -127,7 +127,7 @@ if (!dbh->methods) { PDO_DBG_INF("Throwing exception"); - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } Index: ext/pdo_firebird/firebird_driver.c =================================================================== --- ext/pdo_firebird/firebird_driver.c (revision 292727) +++ ext/pdo_firebird/firebird_driver.c (working copy) @@ -691,7 +691,7 @@ char errmsg[512]; ISC_STATUS *s = H->isc_status; isc_interprete(errmsg, &s); - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), H->isc_status[1] TSRMLS_CC, "SQLSTATE[%s] [%d] %s", "HY000", H->isc_status[1], errmsg); } Index: ext/pdo_pgsql/pgsql_driver.c =================================================================== --- ext/pdo_pgsql/pgsql_driver.c (revision 292727) +++ ext/pdo_pgsql/pgsql_driver.c (working copy) @@ -87,7 +87,7 @@ } if (!dbh->methods) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s", *pdo_err, einfo->errcode, einfo->errmsg); } Index: ext/pdo_odbc/odbc_driver.c =================================================================== --- ext/pdo_odbc/odbc_driver.c (revision 292727) +++ ext/pdo_odbc/odbc_driver.c (working copy) @@ -104,7 +104,7 @@ strcpy(*pdo_err, einfo->last_state); /* printf("@@ SQLSTATE[%s] %s\n", *pdo_err, einfo->last_err_msg); */ if (!dbh->methods) { - zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] %s: %d %s", + zend_throw_exception_ex(php_pdo_get_exception(), einfo->last_error TSRMLS_CC, "SQLSTATE[%s] %s: %d %s", *pdo_err, what, einfo->last_error, einfo->last_err_msg); } ------------------------------------------------------------------------ [2010-01-12 03:36:33] j...@php.net Description: ------------ >From user report in ##PHP/freenode: Each of the PDO drivers explicitly sets the 'code' property of their PDOException to 0, instead of passing along the driver-specific error code. I will attach is a set of proposed patches (against HEAD and 5.3.2 branch as of 2009-01-11) that I believe would fix this for each driver (although I'm guessing on the dblib - it used a significantly different model by storing the error state in DBLIB_G). The example is from the sqlite driver - you can see that an error #14 gets stored in the 'message', but doesn't get passed to the 'code'. Reproduce code: --------------- try { $a = new PDO("sqlite:/this/path/should/not/exist.db"); } catch (PDOException $e) { var_dump($e->getCode()); } Expected result: ---------------- int(14) Actual result: -------------- int(0) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50728&edit=1