Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:46652 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11118 invoked from network); 12 Jan 2010 03:47:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2010 03:47:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=joey@joeysmith.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=joey@joeysmith.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain joeysmith.com designates 209.90.98.146 as permitted sender) X-PHP-List-Original-Sender: joey@joeysmith.com X-Host-Fingerprint: 209.90.98.146 host-3.pl1071314.fiber.net Received: from [209.90.98.146] ([209.90.98.146:34175] helo=joeysmith.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 56/D5-26332-EC0FB4B4 for ; Mon, 11 Jan 2010 22:47:27 -0500 Received: from joey by joeysmith.com with local (Exim 4.69) (envelope-from ) id 1NUXjD-000183-9q for internals@lists.php.net; Mon, 11 Jan 2010 20:47:35 -0700 Date: Mon, 11 Jan 2010 20:47:35 -0700 To: internals@lists.php.net Message-ID: <20100112034735.GA3815@joeysmith.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="k+w/mQv8wyuph6w0" Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Subject: Passing error codes through to PDOException From: joey@joeysmith.com (Joey Smith) --k+w/mQv8wyuph6w0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Maybe I'm up in the night, but I've just opened 50728 because I discovered that all the PDO drivers had a hardcoded 0 where I would expect to see the driver-specific error - a user reported this in ##PHP on Freenode and I take a stab at writing the patches that would let the individual drivers pass their error code on to the user. They're attached to the bug as comments (the first against the tip of 5.3.2 [svn #293440] and the second against HEAD [svn #293440]) - but I'm also attaching them as udiffs to this email. If there's a reason that the PDOExceptions don't contain their driver-specific error codes, feel free to ignore this. --k+w/mQv8wyuph6w0 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pdo_exception_code_5_3_2.patch" Index: ext/pdo_oci/oci_driver.c =================================================================== --- ext/pdo_oci/oci_driver.c (revision 293440) +++ ext/pdo_oci/oci_driver.c (working copy) @@ -173,7 +173,7 @@ /* 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: ext/pdo_dblib/dblib_driver.c =================================================================== --- ext/pdo_dblib/dblib_driver.c (revision 293440) +++ ext/pdo_dblib/dblib_driver.c (working copy) @@ -255,7 +255,7 @@ 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: ext/pdo_sqlite/sqlite_driver.c =================================================================== --- ext/pdo_sqlite/sqlite_driver.c (revision 293440) +++ ext/pdo_sqlite/sqlite_driver.c (working copy) @@ -78,7 +78,7 @@ } 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: ext/pdo_mysql/mysql_driver.c =================================================================== --- ext/pdo_mysql/mysql_driver.c (revision 293440) +++ ext/pdo_mysql/mysql_driver.c (working copy) @@ -127,7 +127,7 @@ 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: ext/pdo_firebird/firebird_driver.c =================================================================== --- ext/pdo_firebird/firebird_driver.c (revision 293440) +++ ext/pdo_firebird/firebird_driver.c (working copy) @@ -691,7 +691,7 @@ 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: ext/pdo_pgsql/pgsql_driver.c =================================================================== --- ext/pdo_pgsql/pgsql_driver.c (revision 293440) +++ ext/pdo_pgsql/pgsql_driver.c (working copy) @@ -87,7 +87,7 @@ } 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: ext/pdo_odbc/odbc_driver.c =================================================================== --- ext/pdo_odbc/odbc_driver.c (revision 293440) +++ ext/pdo_odbc/odbc_driver.c (working copy) @@ -104,7 +104,7 @@ 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); } --k+w/mQv8wyuph6w0 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pdo_exception_code_HEAD.patch" Index: ext/pdo_oci/oci_driver.c =================================================================== --- ext/pdo_oci/oci_driver.c (revision 293440) +++ ext/pdo_oci/oci_driver.c (working copy) @@ -173,7 +173,7 @@ /* 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: ext/pdo_dblib/dblib_driver.c =================================================================== --- ext/pdo_dblib/dblib_driver.c (revision 293440) +++ ext/pdo_dblib/dblib_driver.c (working copy) @@ -255,7 +255,7 @@ 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: ext/pdo_sqlite/sqlite_driver.c =================================================================== --- ext/pdo_sqlite/sqlite_driver.c (revision 293440) +++ ext/pdo_sqlite/sqlite_driver.c (working copy) @@ -102,7 +102,7 @@ } 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: ext/pdo_mysql/mysql_driver.c =================================================================== --- ext/pdo_mysql/mysql_driver.c (revision 293440) +++ ext/pdo_mysql/mysql_driver.c (working copy) @@ -127,7 +127,7 @@ 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: ext/pdo_firebird/firebird_driver.c =================================================================== --- ext/pdo_firebird/firebird_driver.c (revision 293440) +++ ext/pdo_firebird/firebird_driver.c (working copy) @@ -686,7 +686,7 @@ 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: ext/pdo_pgsql/pgsql_driver.c =================================================================== --- ext/pdo_pgsql/pgsql_driver.c (revision 293440) +++ ext/pdo_pgsql/pgsql_driver.c (working copy) @@ -87,7 +87,7 @@ } 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: ext/pdo_odbc/odbc_driver.c =================================================================== --- ext/pdo_odbc/odbc_driver.c (revision 293440) +++ ext/pdo_odbc/odbc_driver.c (working copy) @@ -88,10 +88,10 @@ /* 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", + zend_throw_exception_ex(php_pdo_get_exception(TSRMLS_C), einfo->last_error TSRMLS_CC, "SQLSTATE[%s] %s: %d %s", *pdo_err, what, einfo->last_error, einfo->last_err_msg); #endif } --k+w/mQv8wyuph6w0--