Skip to content

Commit c2ed5e6

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #50728 (All PDOExceptions hardcode 'code' property to 0)
1 parent cf881fc commit c2ed5e6

File tree

8 files changed

+23
-13
lines changed

8 files changed

+23
-13
lines changed

ext/pdo_dblib/dblib_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static int pdo_dblib_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
255255
dbh->driver_data = H;
256256

257257
if (!ret) {
258-
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC,
258+
zend_throw_exception_ex(php_pdo_get_exception(), DBLIB_G(err).dberr TSRMLS_CC,
259259
"SQLSTATE[%s] %s (severity %d)",
260260
DBLIB_G(err).sqlstate,
261261
DBLIB_G(err).dberrstr,

ext/pdo_firebird/firebird_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ static int pdo_firebird_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRM
686686
char errmsg[512];
687687
ISC_STATUS *s = H->isc_status;
688688
isc_interprete(errmsg, &s);
689-
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
689+
zend_throw_exception_ex(php_pdo_get_exception(), H->isc_status[1] TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
690690
"HY000", H->isc_status[1], errmsg);
691691
}
692692

ext/pdo_mysql/mysql_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
127127

128128
if (!dbh->methods) {
129129
PDO_DBG_INF("Throwing exception");
130-
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
130+
zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
131131
*pdo_err, einfo->errcode, einfo->errmsg);
132132
}
133133

ext/pdo_oci/oci_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ ub4 _oci_error(OCIError *err, pdo_dbh_t *dbh, pdo_stmt_t *stmt, char *what, swor
173173

174174
/* little mini hack so that we can use this code from the dbh ctor */
175175
if (!dbh->methods) {
176-
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s]: %s", *pdo_err, einfo->errmsg);
176+
zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s]: %s", *pdo_err, einfo->errmsg);
177177
}
178178

179179
return einfo->errcode;

ext/pdo_odbc/odbc_driver.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,9 @@ void pdo_odbc_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, PDO_ODBC_HSTMT statement,
8585
einfo->what = what;
8686

8787
strcpy(*pdo_err, einfo->last_state);
88-
/* printf("@@ SQLSTATE[%s] %s\n", *pdo_err, einfo->last_err_msg); */
8988
if (!dbh->methods) {
90-
#if PHP_VERSION_ID > 50200
91-
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] %s: %d %s",
89+
zend_throw_exception_ex(php_pdo_get_exception(), einfo->last_error TSRMLS_CC, "SQLSTATE[%s] %s: %d %s",
9290
*pdo_err, what, einfo->last_error, einfo->last_err_msg);
93-
#else
94-
zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), 0 TSRMLS_CC, "SQLSTATE[%s] %s: %d %s",
95-
*pdo_err, what, einfo->last_error, einfo->last_err_msg);
96-
#endif
9791
}
9892
}
9993
/* }}} */

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char *
8787
}
8888

8989
if (!dbh->methods) {
90-
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
90+
zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
9191
*pdo_err, einfo->errcode, einfo->errmsg);
9292
}
9393

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int li
102102
}
103103

104104
if (!dbh->methods) {
105-
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
105+
zend_throw_exception_ex(php_pdo_get_exception(), einfo->errcode TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
106106
*pdo_err, einfo->errcode, einfo->errmsg);
107107
}
108108

ext/pdo_sqlite/tests/bug50728.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #50728 (All PDOExceptions hardcode 'code' property to 0)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
6+
?>
7+
--FILE--
8+
<?php
9+
try {
10+
$a = new PDO("sqlite:/this/path/should/not/exist.db");
11+
} catch (PDOException $e) {
12+
var_dump($e->getCode());
13+
}
14+
?>
15+
--EXPECTF--
16+
int(14)

0 commit comments

Comments
 (0)