]> granicus.if.org Git - php/commitdiff
Correctly report errors for statment problems.
authorIlia Alshanetsky <iliaa@php.net>
Thu, 20 May 2004 16:13:13 +0000 (16:13 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Thu, 20 May 2004 16:13:13 +0000 (16:13 +0000)
ext/pdo_mysql/mysql_driver.c
ext/pdo_mysql/mysql_statement.c
ext/pdo_mysql/php_pdo_mysql_int.h

index d5035534dafee19569868de5ce36ab45a2e9aa71..27c447438d49c29e69410f6b2b7b6f029b04e15f 100755 (executable)
 #include "php_pdo_mysql.h"
 #include "php_pdo_mysql_int.h"
 
-int _pdo_mysql_error(pdo_dbh_t *dbh, const char *file, int line TSRMLS_DC) /* {{{ */
+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 = &dbh->error_code;
+       enum 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);
index 822273961ec802a53ab272de0c8ac5d1a9dc0f32..b8e19854e994e124d0258e307112b7458efaae27 100755 (executable)
@@ -63,11 +63,11 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC)
                }
        }
        if (mysql_real_query(H->server, stmt->active_query_string, stmt->active_query_stringlen) != 0) {
-               pdo_mysql_error(dbh);
+               pdo_mysql_error_stmt(stmt);
                return 0;
        }
        if ((S->result = mysql_use_result(H->server)) == NULL) {
-               pdo_mysql_error(dbh);
+               pdo_mysql_error_stmt(stmt);
                return 0;
        }
        if (!stmt->executed) { 
@@ -91,7 +91,7 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt TSRMLS_DC)
        }
        if((S->current_data = mysql_fetch_row(S->result)) == NULL) {
                /* there seems to be no way of distinguishing 'no data' from 'error' */
-               pdo_mysql_error(stmt->dbh);
+               pdo_mysql_error_stmt(stmt);
                return 0;
        } 
        S->current_lengths = mysql_fetch_lengths(S->result);
@@ -138,7 +138,7 @@ static int pdo_mysql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsig
        }
        if(colno >= mysql_num_fields(S->result)) {
                /* error invalid column */
-               pdo_mysql_error(stmt->dbh);
+               pdo_mysql_error_stmt(stmt);
                return 0;
        }
        *ptr = S->current_data[colno];
index 875738ccaf4d44900c0289c4a808aa9de06ee98c..8ff4f5a7c1b7d4120cad2a6ca25ab1d222dfe1fc 100755 (executable)
@@ -61,8 +61,9 @@ typedef struct {
 
 extern pdo_driver_t pdo_mysql_driver;
 
-extern int _pdo_mysql_error(pdo_dbh_t *dbh, const char *file, int line TSRMLS_DC);
-#define pdo_mysql_error(s) _pdo_mysql_error(s, __FILE__, __LINE__ TSRMLS_DC)
+extern int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC);
+#define pdo_mysql_error(s) _pdo_mysql_error(s, NULL, __FILE__, __LINE__ TSRMLS_DC)
+#define pdo_mysql_error_stmt(s) _pdo_mysql_error(stmt->dbh, stmt, __FILE__, __LINE__ TSRMLS_DC)
 
 extern struct pdo_stmt_methods mysql_stmt_methods;
 #endif