]> granicus.if.org Git - php/commitdiff
fully distinguish between database and statement level errors
authorHartmut Holzgraefe <hholzgra@php.net>
Sun, 27 Feb 2005 20:34:36 +0000 (20:34 +0000)
committerHartmut Holzgraefe <hholzgra@php.net>
Sun, 27 Feb 2005 20:34:36 +0000 (20:34 +0000)
ext/pdo_mysql/mysql_driver.c
ext/pdo_mysql/mysql_statement.c
ext/pdo_mysql/php_pdo_mysql_int.h

index eb8798449fddf8fa62252c77383c1bd08c8cc221..4e1ab8a82219b47d84d3717cf4ea9dc40d00b656 100755 (executable)
@@ -44,10 +44,19 @@ const char *pdo_mysql_get_sqlstate(unsigned int my_errno) {
 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;
+       pdo_error_type *pdo_err
+       pdo_mysql_error_info *einfo;
        char *sqlstate = NULL;
 
+       if (stmt) {
+               pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
+               pdo_err = &stmt->error_code;
+               einfo   = &S->einfo;
+       } else {
+               pdo_err = &dbh->error_code;
+               einfo   = &H->einfo;
+       }
+
        einfo->errcode = mysql_errno(H->server);
        einfo->file = file;
        einfo->line = line;
@@ -64,13 +73,13 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
                return 0;
        }
 
+       strcpy(*pdo_err, pdo_mysql_get_sqlstate(einfo->errcode));
+
        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;
 }
 /* }}} */
@@ -80,6 +89,13 @@ static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in
        pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
        pdo_mysql_error_info *einfo = &H->einfo;
 
+       if (stmt) {
+               pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
+               einfo = &S->einfo;
+       } else {
+               einfo = &H->einfo;
+       }
+
        if (einfo->errcode) {
                add_next_index_long(info, einfo->errcode);
                add_next_index_string(info, einfo->errmsg, 1);
index b7d423173d4f3afa687b87d299f0007132bb1d82..11d81136f28486623d593fa5b3a4e1241dcaf47d 100755 (executable)
@@ -40,6 +40,10 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC)
                mysql_free_result(S->result);
                S->result = NULL;
        }
+       if (S->einfo.errmsg) {
+               efree(S->einfo.errmsg);
+               S->einfo.errmsg = NULL;
+       }
        efree(S);
        return 1;
 }
index 888a6055919858bbe7ae0cb4726b6cc8fec03ba6..4dc5739793afbd4dad3e3980502a946f11823ecd 100755 (executable)
@@ -50,6 +50,7 @@ typedef struct {
        MYSQL_FIELD         *fields;
        MYSQL_ROW               current_data;
        long                    *current_lengths;
+       pdo_mysql_error_info einfo;
 } pdo_mysql_stmt;
 
 typedef struct {