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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to