]> granicus.if.org Git - php/commitdiff
Fixed bug #50728 (All PDOExceptions hardcode 'code' property to 0)
authorIlia Alshanetsky <iliaa@php.net>
Tue, 12 Jan 2010 12:46:54 +0000 (12:46 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 12 Jan 2010 12:46:54 +0000 (12:46 +0000)
NEWS
ext/pdo_dblib/dblib_driver.c
ext/pdo_firebird/firebird_driver.c
ext/pdo_mysql/mysql_driver.c
ext/pdo_oci/oci_driver.c
ext/pdo_odbc/odbc_driver.c
ext/pdo_pgsql/pgsql_driver.c
ext/pdo_sqlite/sqlite_driver.c
ext/pdo_sqlite/tests/bug50728.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 5447487b27818289c4464fda46509e8fc576d339..1e40ba8454aac2207b2c4f0180bb2b2a938ec7c5 100644 (file)
--- 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)
index dd283734b96d88c10360a17484d57e035ebc3d06..2b604db1484cce3478fb41422becc4cc58b7734c 100644 (file)
@@ -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,
index fe470b96e3d1b6f3d543a8d09140107a3a1971eb..dc2f4e7511fa0d1904cf4f1642dfcf346e1fb6bb 100644 (file)
@@ -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);
        }
 
index 04ee08174c08728908a62220910a8bf6e6a10725..2f6a9be99c51a9b5d31933f56a9de3953fbccd56 100755 (executable)
@@ -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);
        }
 
index 3bb7255c967793154d4675ba1fc16ac93dd7d7de..52a23a9d1531eae0bc60abfb7a0f16e10a4c8b29 100755 (executable)
@@ -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;
index 6a7b0b6e4e7f60f2e552f72fc6bc5036f74aa28a..e014bd7bec75d70abc92e0b3a6e430d35f16942b 100755 (executable)
@@ -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);
        }
 
index 2109fa10c2f6dfc148c99abaff789ab78989a15a..f2467e8a6634e3ea2920cbc0940cd3de6aacf8b4 100644 (file)
@@ -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);
        }
        
index e945f2ccd0274ac7aeb25cecc663f470c88ba4df..7ad7722c9d8d06f236303f70a8e858a73e132c76 100644 (file)
@@ -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 (file)
index 0000000..3dbbb1f
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+Bug #50728 (All PDOExceptions hardcode 'code' property to 0)
+--SKIPIF--
+<?php
+if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
+?>
+--FILE--
+<?php
+try {
+       $a = new PDO("sqlite:/this/path/should/not/exist.db");
+} catch (PDOException $e) {
+       var_dump($e->getCode());
+}
+?>
+--EXPECTF--
+int(14)