wez             Sun Oct  2 18:11:19 2005 EDT

  Added files:                 (Branch: PHP_5_1)
    /php-src/ext/pdo/tests      bug_34687.phpt 

  Modified files:              
    /php-src/ext/pdo    pdo_dbh.c php_pdo_driver.h php_pdo_int.h 
  Log:
  Fix Bug #34687; error information from query() not passed back
  
  
http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_dbh.c?r1=1.82.2.7&r2=1.82.2.8&ty=u
Index: php-src/ext/pdo/pdo_dbh.c
diff -u php-src/ext/pdo/pdo_dbh.c:1.82.2.7 php-src/ext/pdo/pdo_dbh.c:1.82.2.8
--- php-src/ext/pdo/pdo_dbh.c:1.82.2.7  Sun Oct  2 16:38:18 2005
+++ php-src/ext/pdo/pdo_dbh.c   Sun Oct  2 18:11:17 2005
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pdo_dbh.c,v 1.82.2.7 2005/10/02 20:38:18 helly Exp $ */
+/* $Id: pdo_dbh.c,v 1.82.2.8 2005/10/02 22:11:17 wez Exp $ */
 
 /* The PDO Database Handle Class */
 
@@ -919,6 +919,10 @@
        }
        PDO_CONSTRUCT_CHECK;
 
+       if (dbh->query_stmt) {
+               RETURN_STRING(dbh->query_stmt->error_code, 1);
+       }
+       
        RETURN_STRING(dbh->error_code, 1);
 }
 /* }}} */
@@ -935,10 +939,14 @@
        PDO_CONSTRUCT_CHECK;
 
        array_init(return_value);
-       add_next_index_string(return_value, dbh->error_code, 1);
 
+       if (dbh->query_stmt) {
+               add_next_index_string(return_value, 
dbh->query_stmt->error_code, 1);
+       } else {
+               add_next_index_string(return_value, dbh->error_code, 1);
+       }
        if (dbh->methods->fetch_err) {
-               dbh->methods->fetch_err(dbh, NULL, return_value TSRMLS_CC);
+               dbh->methods->fetch_err(dbh, dbh->query_stmt, return_value 
TSRMLS_CC);
        }
 }
 /* }}} */
@@ -981,8 +989,6 @@
 
        if (dbh->methods->preparer(dbh, statement, statement_len, stmt, NULL 
TSRMLS_CC)) {
                if (ZEND_NUM_ARGS() == 1 || SUCCESS == 
pdo_stmt_setup_fetch_mode(INTERNAL_FUNCTION_PARAM_PASSTHRU, stmt, 1)) {
-                       PDO_STMT_CLEAR_ERR();
-
                        /* now execute the statement */
                        PDO_STMT_CLEAR_ERR();
                        if (stmt->methods->executer(stmt TSRMLS_CC)) {
@@ -1000,13 +1006,14 @@
                        }
                }
                /* something broke */
+               dbh->query_stmt = stmt;
+               dbh->query_stmt_zval = *return_value;
+               PDO_HANDLE_STMT_ERR();
+       } else {
+               PDO_HANDLE_DBH_ERR();
+               zval_dtor(return_value);
        }
 
-       PDO_HANDLE_STMT_ERR();
-               
-       /* kill the object handle for the stmt here */
-       zval_dtor(return_value);
-
        RETURN_FALSE;
 }
 /* }}} */
http://cvs.php.net/diff.php/php-src/ext/pdo/php_pdo_driver.h?r1=1.66.2.2&r2=1.66.2.3&ty=u
Index: php-src/ext/pdo/php_pdo_driver.h
diff -u php-src/ext/pdo/php_pdo_driver.h:1.66.2.2 
php-src/ext/pdo/php_pdo_driver.h:1.66.2.3
--- php-src/ext/pdo/php_pdo_driver.h:1.66.2.2   Sun Oct  2 16:07:11 2005
+++ php-src/ext/pdo/php_pdo_driver.h    Sun Oct  2 18:11:17 2005
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_pdo_driver.h,v 1.66.2.2 2005/10/02 20:07:11 helly Exp $ */
+/* $Id: php_pdo_driver.h,v 1.66.2.3 2005/10/02 22:11:17 wez Exp $ */
 
 #ifndef PHP_PDO_DRIVER_H
 #define PHP_PDO_DRIVER_H
@@ -44,7 +44,7 @@
 # define FALSE 0
 #endif
 
-#define PDO_DRIVER_API 20050711
+#define PDO_DRIVER_API 20051002
 
 enum pdo_param_type {
        PDO_PARAM_NULL,
@@ -477,8 +477,14 @@
        pdo_driver_t *driver;
        
        zend_class_entry *def_stmt_ce;
-       
        zval *def_stmt_ctor_args;
+
+       /* when calling PDO::query(), we need to keep the error
+        * context from the statement around until we next clear it.
+        * This will allow us to report the correct error message
+        * when PDO::query() fails */
+       pdo_stmt_t *query_stmt;
+       zval query_stmt_zval;
 };
 
 /* describes a column */
http://cvs.php.net/diff.php/php-src/ext/pdo/php_pdo_int.h?r1=1.17.2.3&r2=1.17.2.4&ty=u
Index: php-src/ext/pdo/php_pdo_int.h
diff -u php-src/ext/pdo/php_pdo_int.h:1.17.2.3 
php-src/ext/pdo/php_pdo_int.h:1.17.2.4
--- php-src/ext/pdo/php_pdo_int.h:1.17.2.3      Sun Oct  2 16:38:18 2005
+++ php-src/ext/pdo/php_pdo_int.h       Sun Oct  2 18:11:17 2005
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_pdo_int.h,v 1.17.2.3 2005/10/02 20:38:18 helly Exp $ */
+/* $Id: php_pdo_int.h,v 1.17.2.4 2005/10/02 22:11:17 wez Exp $ */
 
 /* Stuff private to the PDO extension and not for consumption by PDO drivers
  * */
@@ -57,7 +57,13 @@
 
 extern void pdo_handle_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt TSRMLS_DC);
 
-#define PDO_DBH_CLEAR_ERR()            strcpy(dbh->error_code, PDO_ERR_NONE)
+#define PDO_DBH_CLEAR_ERR()            do { \
+       strcpy(dbh->error_code, PDO_ERR_NONE); \
+       if (dbh->query_stmt) { \
+               dbh->query_stmt = NULL; \
+               zend_objects_store_del_ref(&dbh->query_stmt_zval TSRMLS_CC); \
+       } \
+} while (0)
 #define PDO_STMT_CLEAR_ERR()   strcpy(stmt->error_code, PDO_ERR_NONE)
 #define PDO_HANDLE_DBH_ERR()   if (strcmp(dbh->error_code, PDO_ERR_NONE)) { 
pdo_handle_error(dbh, NULL TSRMLS_CC); }
 #define PDO_HANDLE_STMT_ERR()  if (strcmp(stmt->error_code, PDO_ERR_NONE)) { 
pdo_handle_error(stmt->dbh, stmt TSRMLS_CC); }

http://cvs.php.net/co.php/php-src/ext/pdo/tests/bug_34687.phpt?r=1.1&p=1
Index: php-src/ext/pdo/tests/bug_34687.phpt
+++ php-src/ext/pdo/tests/bug_34687.phpt

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to