Fixed bug #50728 (All PDOExceptions hardcode 'code' property to 0)

This commit is contained in:
Ilia Alshanetsky 2010-01-12 12:46:54 +00:00
parent e3f76cc8c3
commit d2e14e3f20
9 changed files with 25 additions and 7 deletions

2
NEWS
View File

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

View 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,

View 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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}

View 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);
}

View 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);
}

View File

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