fully distinguish between database and statement level errors

This commit is contained in:
Hartmut Holzgraefe 2005-02-27 20:34:36 +00:00
parent 86994c3357
commit f7e8fcb8e0
3 changed files with 25 additions and 4 deletions

View File

@ -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);

View File

@ -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;
}

View File

@ -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 {