summaryrefslogtreecommitdiff
path: root/ext/pdo_mysql
diff options
context:
space:
mode:
authorHartmut Holzgraefe <hholzgra@php.net>2005-02-27 11:39:15 +0000
committerHartmut Holzgraefe <hholzgra@php.net>2005-02-27 11:39:15 +0000
commitd3fcc41be7e45a978cd2584ae5d2a0542e116a4e (patch)
tree8a88f6d5632a3ee05ac034ba1534868e7da49b0b /ext/pdo_mysql
parent4c4ec3c5db84e1a6d9e752088a86215bc7fd2146 (diff)
downloadphp-git-d3fcc41be7e45a978cd2584ae5d2a0542e116a4e.tar.gz
use auto generated error -> state mappings
Diffstat (limited to 'ext/pdo_mysql')
-rwxr-xr-xext/pdo_mysql/mysql_driver.c55
-rw-r--r--ext/pdo_mysql/package.xml1
2 files changed, 15 insertions, 41 deletions
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c
index b31ad28184..d2052d1485 100755
--- a/ext/pdo_mysql/mysql_driver.c
+++ b/ext/pdo_mysql/mysql_driver.c
@@ -29,13 +29,24 @@
#include "pdo/php_pdo_driver.h"
#include "php_pdo_mysql.h"
#include "php_pdo_mysql_int.h"
+#include <mysqld_error.h>
#include "zend_exceptions.h"
+
+const char *pdo_mysql_get_sqlstate(unsigned int my_errno) {
+ switch (my_errno) {
+ /* import auto-generated case: code */
+#include "php_pdo_mysql_sqlstate.h"
+ default: return "HY000";
+ }
+}
+
int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC) /* {{{ */
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
pdo_mysql_error_info *einfo = &H->einfo;
+ char *sqlstate = NULL;
einfo->errcode = mysql_errno(H->server);
einfo->file = file;
@@ -53,51 +64,13 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
return 0;
}
- /* mapping taken from:
- http://dev.mysql.com/doc/mysql/en/Error-handling.html
- */
- switch (einfo->errcode) {
- default:
- case 1000: case 1001: case 1002: case 1003:
- case 1004: case 1005: case 1006: case 1007:
- case 1008: case 1009: case 1010: case 1011:
- case 1012: case 1013: case 1014: case 1015:
- case 1016: case 1017: case 1018: case 1019:
- case 1020: case 1021: case 1023: case 1024:
- case 1025: case 1026: case 1027: case 1028:
- case 1029: case 1030: case 1031: case 1032:
- case 1034: case 1035: case 1036: case 1039:
- case 1041:
- strcpy(*pdo_err, "HY000");
- break;
- case 1022:
- strcpy(*pdo_err, "23000");
- break;
- case 1037: case 1038:
- strcpy(*pdo_err, "HY001");
- break;
- case 1040:
- strcpy(*pdo_err, "08004");
- break;
- case 1042: case 1043:
- strcpy(*pdo_err, "08S01");
- break;
- case 1044:
- strcpy(*pdo_err, "42000");
- break;
- case 1045:
- strcpy(*pdo_err, "28000");
- break;
-
- /* TODO: someone with more time on their hands
- * needs to complete this list */
- }
-
if (!dbh->methods) {
zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
*pdo_err, einfo->errcode, einfo->errmsg);
}
-
+
+ strcpy(*pdo_err, pdo_mysql_get_sqlstate(einfo->errcode));
+
return einfo->errcode;
}
/* }}} */
diff --git a/ext/pdo_mysql/package.xml b/ext/pdo_mysql/package.xml
index d6e641bc46..77b3aa144a 100644
--- a/ext/pdo_mysql/package.xml
+++ b/ext/pdo_mysql/package.xml
@@ -37,6 +37,7 @@
<file role="src" name="mysql_statement.c"/>
<file role="src" name="php_pdo_mysql.h"/>
<file role="src" name="php_pdo_mysql_int.h"/>
+ <file role="src" name="php_pdo_mysql_sqlstate.h"/>
<file role="doc" name="CREDITS"/>
</filelist>