From: Hartmut Holzgraefe Date: Sun, 27 Feb 2005 20:34:36 +0000 (+0000) Subject: fully distinguish between database and statement level errors X-Git-Tag: RELEASE_0_3~152 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7e8fcb8e0b3a2110c31e05c4cc2a55ddaf584f6;p=php fully distinguish between database and statement level errors --- diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index eb8798449f..4e1ab8a822 100755 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -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); diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index b7d423173d..11d81136f2 100755 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -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; } diff --git a/ext/pdo_mysql/php_pdo_mysql_int.h b/ext/pdo_mysql/php_pdo_mysql_int.h index 888a605591..4dc5739793 100755 --- a/ext/pdo_mysql/php_pdo_mysql_int.h +++ b/ext/pdo_mysql/php_pdo_mysql_int.h @@ -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 {