From d2e14e3f202d1c30dd79c095ff27bf96a146b813 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Tue, 12 Jan 2010 12:46:54 +0000 Subject: [PATCH] Fixed bug #50728 (All PDOExceptions hardcode 'code' property to 0) --- NEWS | 2 ++ ext/pdo_dblib/dblib_driver.c | 2 +- ext/pdo_firebird/firebird_driver.c | 2 +- ext/pdo_mysql/mysql_driver.c | 2 +- ext/pdo_oci/oci_driver.c | 2 +- ext/pdo_odbc/odbc_driver.c | 2 +- ext/pdo_pgsql/pgsql_driver.c | 2 +- ext/pdo_sqlite/sqlite_driver.c | 2 +- ext/pdo_sqlite/tests/bug50728.phpt | 16 ++++++++++++++++ 9 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 ext/pdo_sqlite/tests/bug50728.phpt diff --git a/NEWS b/NEWS index 5447487b27..1e40ba8454 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,8 @@ PHP NEWS (Ilia) - Added stream_resolve_include_path(). (Mikko) +- Fixed bug #50728 (All PDOExceptions hardcode 'code' property to 0). (Joey, + Ilia) - Fixed bug #50680 (strtotime() does not support eighth ordinal number). (Ilia) - Fixed bug #50661 (DOMDocument::loadXML does not allow UTF-16). (Rob) diff --git a/ext/pdo_dblib/dblib_driver.c b/ext/pdo_dblib/dblib_driver.c index dd283734b9..2b604db148 100644 --- a/ext/pdo_dblib/dblib_driver.c +++ b/ext/pdo_dblib/dblib_driver.c @@ -255,7 +255,7 @@ cleanup: 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, diff --git a/ext/pdo_firebird/firebird_driver.c b/ext/pdo_firebird/firebird_driver.c index fe470b96e3..dc2f4e7511 100644 --- a/ext/pdo_firebird/firebird_driver.c +++ b/ext/pdo_firebird/firebird_driver.c @@ -691,7 +691,7 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRM 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); } diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 04ee08174c..2f6a9be99c 100755 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -127,7 +127,7 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin 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); } diff --git a/ext/pdo_oci/oci_driver.c b/ext/pdo_oci/oci_driver.c index 3bb7255c96..52a23a9d15 100755 --- a/ext/pdo_oci/oci_driver.c +++ b/ext/pdo_oci/oci_driver.c @@ -173,7 +173,7 @@ ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, swor /* 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; diff --git a/ext/pdo_odbc/odbc_driver.c b/ext/pdo_odbc/odbc_driver.c index 6a7b0b6e4e..e014bd7bec 100755 --- a/ext/pdo_odbc/odbc_driver.c +++ b/ext/pdo_odbc/odbc_driver.c @@ -104,7 +104,7 @@ void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement, 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); } diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index 2109fa10c2..f2467e8a66 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -87,7 +87,7 @@ int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char * } 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); } diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c index e945f2ccd0..7ad7722c9d 100644 --- a/ext/pdo_sqlite/sqlite_driver.c +++ b/ext/pdo_sqlite/sqlite_driver.c @@ -78,7 +78,7 @@ int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int li } 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); } diff --git a/ext/pdo_sqlite/tests/bug50728.phpt b/ext/pdo_sqlite/tests/bug50728.phpt new file mode 100644 index 0000000000..3dbbb1ffff --- /dev/null +++ b/ext/pdo_sqlite/tests/bug50728.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #50728 (All PDOExceptions hardcode 'code' property to 0) +--SKIPIF-- + +--FILE-- +getCode()); +} +?> +--EXPECTF-- +int(14) -- 2.40.0