]> 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_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 59faf9c695dce901902de3c97024e3d04f004a87..1894b24dc1723ea2c007e962624668a3ad184ba7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ PHP                                                                        NEWS
 
 - Fixed build of mysqli with MySQL 5.5.0-m2. (Andrey)
 
+- 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 0f9a82dc1ab949a6a28d71ab522d763afb6f9b14..299f39089102dabd2ad9053ddbdeb53e438202d3 100755 (executable)
@@ -106,7 +106,7 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
 #endif
 
        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);
        }
 /* printf("** [%s:%d] %s %s\n", file, line, *pdo_err, 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 58a3f9354e497d3c979bb4429bcbeef093cf4f09..c1456622494f57d1cfd5446ee86d5f0c4797fcc0 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 c80f37672e3819d94e6175c5ac48de838dcf8efc..da80c6783509c923a53e21df2aa1c864dc598da3 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 f162bcd9421293f95379a54e99f432d1bd629cf2..d11d5735be4a91ad655b4620ed4f5b8b7aa2e489 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)