From f2dc3a258d1ff64739e4e9e740b6431ec434f78e Mon Sep 17 00:00:00 2001 From: Georg Richter Date: Mon, 1 Nov 2004 07:57:46 +0000 Subject: [PATCH] MFH: Fixed tests for empty dates (see http://bugs.mysql.com/?id=6058) Fixed memleak in mysqli_stmt_bind_result Fixed error handling for mysqli_multi_query --- ext/mysqli/mysqli_api.c | 21 +++++++++++---------- ext/mysqli/mysqli_nonapi.c | 21 ++++++++++++++++++--- ext/mysqli/tests/003.phpt | 2 +- ext/mysqli/tests/020.phpt | 2 +- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 3d333bcbfa..9c46c4d393 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -217,6 +217,16 @@ PHP_FUNCTION(mysqli_stmt_bind_result) zval *mysql_stmt; MYSQL_BIND *bind; + if (getThis()) { + start = 0; + } + + if (zend_parse_method_parameters((getThis()) ? 0:1 TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) { + return; + } + + MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt"); + if (argc < (getThis() ? 1 : 2)) { WRONG_PARAM_COUNT; } @@ -228,15 +238,6 @@ PHP_FUNCTION(mysqli_stmt_bind_result) WRONG_PARAM_COUNT; } - if (getThis()) { - start = 0; - } - - if (zend_parse_method_parameters((getThis()) ? 0:1 TSRMLS_CC, getThis(), "O", &mysql_stmt, mysqli_stmt_class_entry) == FAILURE) { - return; - } - - MYSQLI_FETCH_RESOURCE(stmt, MY_STMT *, &mysql_stmt, "mysqli_stmt"); var_cnt = argc - start; @@ -601,7 +602,7 @@ PHP_FUNCTION(mysqli_stmt_fetch) if (!(ret = mysql_stmt_fetch(stmt->stmt))) { for (i = 0; i < stmt->result.var_cnt; i++) { if (stmt->result.vars[i]->type == IS_STRING && stmt->result.vars[i]->value.str.len) { - efree(stmt->result.vars[i]->value.str.val); + efree(stmt->result.vars[i]->value.str.val); } if (!stmt->result.is_null[i]) { switch (stmt->result.buf[i].type) { diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index 13a9ee23c5..260c0c75d6 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -50,8 +50,8 @@ PHP_FUNCTION(mysqli_connect) } if (!socket_len) { - socket = NULL; - } + socket = NULL; + } /* TODO: safe mode handling */ if (PG(sql_safe_mode)){ @@ -222,8 +222,23 @@ PHP_FUNCTION(mysqli_multi_query) MYSQLI_ENABLE_MQ; if (mysql_real_query(mysql->mysql, query, query_len)) { - MYSQLI_DISABLE_MQ; + char s_error[MYSQL_ERRMSG_SIZE], s_sqlstate[SQLSTATE_LENGTH+1]; + unsigned int s_errno; MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql); + + /* we have to save error information, cause + MYSQLI_DISABLE_MQ will reset error information */ + strcpy(s_error, mysql_error(mysql->mysql)); + strcpy(s_sqlstate, mysql_sqlstate(mysql->mysql)); + s_errno = mysql_errno(mysql->mysql); + + MYSQLI_DISABLE_MQ; + + /* restore error information */ + strcpy(mysql->mysql->net.last_error, s_error); + strcpy(mysql->mysql->net.sqlstate, s_sqlstate); + mysql->mysql->net.last_errno = s_errno; + RETURN_FALSE; } RETURN_TRUE; diff --git a/ext/mysqli/tests/003.phpt b/ext/mysqli/tests/003.phpt index 5535e9fb40..906bf28dec 100644 --- a/ext/mysqli/tests/003.phpt +++ b/ext/mysqli/tests/003.phpt @@ -50,7 +50,7 @@ array(7) { [4]=> string(19) "2010-07-10 00:00:00" [5]=> - string(0) "" + string(19) "0000-00-00 00:00:00" [6]=> string(19) "1999-12-29 00:00:00" } diff --git a/ext/mysqli/tests/020.phpt b/ext/mysqli/tests/020.phpt index 5aa244329f..d08930fed9 100644 --- a/ext/mysqli/tests/020.phpt +++ b/ext/mysqli/tests/020.phpt @@ -58,7 +58,7 @@ array(7) { [4]=> string(19) "2010-07-10 00:00:00" [5]=> - string(0) "" + string(19) "0000-00-00 00:00:00" [6]=> string(19) "1999-12-29 00:00:00" } -- 2.50.1