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

index 2f68a9d6a9d852700808e138e75ac644ea544ea5..dd597698621b835c8bd27104198f2f8cbe055c45 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 82bc9920bdd4b2ead68ea2336dd8deb67e88df41..e19efa3cf53a6e1c5007e6e41bf54f8e708f3984 100644 (file)
@@ -686,7 +686,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 9774554f378dda9bb5cbcf59dd0f30f439d0003e..52d7437d75704d8ba0e9f1d32c3a9ddf97b983e1 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 0b606eb4c0340ad3ae19f77a852ec2e97b98c6d7..aa3671a0f30345fa0f5517a6b8be31a5eb402948 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 aba37aad231bc3d9ce7d36ce708dd5ecb753d480..fb841ef3a01dc3cdebd7720e57ded4fbb773e83f 100755 (executable)
@@ -85,15 +85,9 @@ void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement,
        einfo->what = what;
 
        strcpy(*pdo_err, einfo->last_state);
-/* 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",
-                               *pdo_err, what, einfo->last_error, einfo->last_err_msg);
-#endif
        }
 }
 /* }}} */
index 4b6b437b2c00c30fea73f7a846e0968a4db347c0..647309e6075011942dfcbf033d6577fc1d8b89f8 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 4a91569d46c3bbf89084ca19417002e77a0191e5..f315d0aa9e8660b87afa183638b44bb4fb5cbecb 100644 (file)
@@ -102,7 +102,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)