]> granicus.if.org Git - php/commitdiff
tidy up some parts of the build (could do with more work)
authorWez Furlong <wez@php.net>
Fri, 7 Jan 2005 05:24:21 +0000 (05:24 +0000)
committerWez Furlong <wez@php.net>
Fri, 7 Jan 2005 05:24:21 +0000 (05:24 +0000)
Partially implement SQLSTATE error codes

ext/pdo_mysql/config.m4
ext/pdo_mysql/mysql_driver.c

index 3b938695992e045954717c18b916a078ff2c5de4..ee6d67971af871b586639e3a0a316579fcf46e8e 100755 (executable)
@@ -2,11 +2,11 @@ dnl
 dnl $Id$
 dnl
 
-AC_DEFUN(MYSQL_LIB_CHK, [
-  str="$MYSQL_DIR/$1/libmysqlclient.*"
+AC_DEFUN(PDO_MYSQL_LIB_CHK, [
+  str="$PDO_MYSQL_DIR/$1/libmysqlclient.*"
   for j in `echo $str`; do
     if test -r $j; then
-      MYSQL_LIB_DIR=$MYSQL_DIR/$1
+      PDO_MYSQL_LIB_DIR=$MYSQL_DIR/$1
       break 2
     fi
   done
@@ -19,35 +19,40 @@ if test "$PHP_PDO_MYSQL" != "no"; then
   AC_DEFINE(HAVE_MYSQL, 1, [Whether you have MySQL])
 
   for i in $PHP_PDO_MYSQL /usr/local /usr ; do
-      MYSQL_DIR=$i
-      PDO_MYSQL_CONFIG=$MYSQL_DIR/bin/mysql_config
+      PDO_MYSQL_DIR=$i
+      PDO_MYSQL_CONFIG=$PDO_MYSQL_DIR/bin/mysql_config
       if test -r $i/include/mysql; then
-       MYSQL_INC_DIR=$i/include/mysql
+       PDO_MYSQL_INC_DIR=$i/include/mysql
       else
-       MYSQL_INC_DIR=$i/include
+       PDO_MYSQL_INC_DIR=$i/include
       fi      
       if test -r $i/lib/mysql; then
-        MYSQL_LIBS=$i/lib/mysql
+        PDO_MYSQL_LIB_DIR=$i/lib/mysql
       else
-        MYSQL_LIBS=$i/lib
+        PDO_MYSQL_LIB_DIR=$i/lib
       fi
       if test -x $PDO_MYSQL_CONFIG; then
         break
       fi
   done
 
-  if test -z "$MYSQL_DIR"; then
+  if test -z "$PDO_MYSQL_DIR"; then
     AC_MSG_ERROR([Cannot find MySQL header files under $PHP_MYSQL.
 Note that the MySQL client library is not bundled anymore.])
   fi
 
-  PDO_MYSQL_LIBS=`$PDO_MYSQL_CONFIG --libs`
-  PDO_MYSQL_SOCKET=`$PDO_MYSQL_CONFIG --socket` 
+  if test -x $PDO_MYSQL_CONFIG; then
+       PDO_MYSQL_SOCKET=`$PDO_MYSQL_CONFIG --socket` 
+  fi
 
   AC_DEFINE_UNQUOTED(PDO_MYSQL_UNIX_ADDR, "$PDO_MYSQL_SOCKET", [ ])
 
-  PHP_ADD_LIBRARY_WITH_PATH(mysqlclient, $MYSQL_LIBS, PDO_MYSQL_SHARED_LIBADD)
-  PHP_ADD_INCLUDE($MYSQL_INC_DIR)
+  PHP_ADD_LIBRARY_WITH_PATH(mysqlclient, $PDO_MYSQL_LIB_DIR, PDO_MYSQL_SHARED_LIBADD)
+  PHP_ADD_INCLUDE($PDO_MYSQL_INC_DIR)
+  if test -x $PDO_MYSQL_CONFIG; then
+       PDO_MYSQL_LIBS=`$PDO_MYSQL_CONFIG --libs`
+       PHP_SUBST_OLD(PDO_MYSQL_LIBS)
+  fi
 
   if test -f $prefix/include/php/ext/pdo/php_pdo_driver.h; then
        pdo_inc_path=$prefix/include/php/ext
@@ -62,7 +67,7 @@ Note that the MySQL client library is not bundled anymore.])
   PHP_NEW_EXTENSION(pdo_mysql, pdo_mysql.c mysql_driver.c mysql_statement.c, $ext_shared,,-I$pdo_inc_path)
   PHP_ADD_EXTENSION_DEP(pdo_mysql, pdo)
   PDO_MYSQL_MODULE_TYPE=external
-  PDO_MYSQL_INCLUDE=-I$MYSQL_INC_DIR
+  PDO_MYSQL_INCLUDE=-I$PDO_MYSQL_INC_DIR
  
   PHP_SUBST(PDO_MYSQL_SHARED_LIBADD)
   PHP_SUBST_OLD(PDO_MYSQL_MODULE_TYPE)
index 80eacfec39a416822270d0cafcc41da11bbb2dee..f0f0da3398104d81f87628fbad2aa56840835946 100755 (executable)
@@ -34,7 +34,7 @@
 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;
-       enum pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
+       pdo_error_type *pdo_err = stmt ? &stmt->error_code : &dbh->error_code;
        pdo_mysql_error_info *einfo = &H->einfo;
 
        einfo->errcode = mysql_errno(H->server);
@@ -49,77 +49,53 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
        if (einfo->errcode) {
                einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent);
        } else { /* no error */
-               *pdo_err = PDO_ERR_NONE;
+               strcpy(*pdo_err, PDO_ERR_NONE);
                return 0;
        }
 
+       /* mapping taken from: 
+               http://dev.mysql.com/doc/mysql/en/Error-handling.html
+       */
        switch (einfo->errcode) {
-               case 1007: /* database already exists */
-               case 1050: /* table already exists */
-               case 1086: /* file already exists */
-               case 1125: /* function already exists */
-                       *pdo_err = PDO_ERR_ALREADY_EXISTS;
+               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 1008: /* database does not exist */
-               case 1029: /* view does not exist */
-               case 1072: /* key column does not exist */
-               case 1091: /* column/key does not exist */
-               case 1146: /* table does not exist */
-               case 1176: /* key not found in table */
-                       *pdo_err = PDO_ERR_NOT_FOUND;
-                       break;  
-
-               case 1152: /* aborted connection */
-               case 1154: /* cannot read from connection pipe */
-               case 1184: /* aborted new connection */
-               case 1159: /* timeout */
-               case 1160: /* timeout */
-               case 1161: /* timeout */
-                       *pdo_err = PDO_ERR_DISCONNECTED;
+               case 1022:
+                       strcpy(*pdo_err, "23000");
                        break;
-
-               case 1089: /* unsupported sub-key */
-               case 1163: /* blob/text not supported inside table */
-               case 1164: /* no auto-incremenet support */
-               case 1174: /* no RAID support */
-               case 1178: /* table handler does not support something */
-               case 1185: /* binary dump not supported */
-               case 1214: /* FULLTEXT not supported */
-               case 1235: /* something not supported by MySQL version */
-                       *pdo_err = PDO_ERR_NOT_IMPLEMENTED;
+               case 1037: case 1038:
+                       strcpy(*pdo_err, "HY001");
                        break;
-
-               case 1252: /* character set mismatch */
-                       *pdo_err = PDO_ERR_MISMATCH;
+               case 1040:
+                       strcpy(*pdo_err, "08004");
                        break;
-
-               case 1264: /* data truncated */
-                       *pdo_err = PDO_ERR_TRUNCATED;
+               case 1042: case 1043:
+                       strcpy(*pdo_err, "08S01");
                        break;
-       
-               case 1169: /* unique constraint */
-               case 1216: /* foreign key constraint */
-               case 1217: /* foreign key constraint */
-                       *pdo_err = PDO_ERR_CONSTRAINT;
+               case 1044:
+                       strcpy(*pdo_err, "42000");
                        break;
-
-               case 1064: /* query parse error */
-               case 1065: /* empty query */
-               /* XXX: MySQL has all sorts of errors that can be considered syntax errors, specifically
-                       dealing with table creation & modifications, do we want to include them here?
-                */
-                       *pdo_err = PDO_ERR_SYNTAX;
+               case 1045:
+                       strcpy(*pdo_err, "28000");
                        break;
 
-               default:
-                       *pdo_err = PDO_ERR_CANT_MAP;
-                       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(), *pdo_err TSRMLS_CC, "[%d] %s",
-                               einfo->errcode, einfo->errmsg);
+               zend_throw_exception_ex(php_pdo_get_exception(), 0 TSRMLS_CC, "SQLSTATE[%s] [%d] %s",
+                               *pdo_err, einfo->errcode, einfo->errmsg);
        }
        
        return einfo->errcode;