From eaaef0d870f50563fab837fffadcf47a02079c54 Mon Sep 17 00:00:00 2001 From: Andrey Hristov Date: Fri, 7 Jan 2011 14:22:30 +0000 Subject: [PATCH] Proper fix for Bug #53503 mysqli::query returns false after successful LOAD DATA query which fixes als #56349, same behavior but in ext/mysql. Both due to a bug in mysqlnd. Never was a problem with libmysql. Also fixed the 53503's test case as it always reported PASS, even when there should have been a failure. --- NEWS | 2 +- ext/mysql/tests/bug53649.phpt | 53 ++++++++++++++++++++++++++++++++++ ext/mysqli/mysqli_nonapi.c | 2 +- ext/mysqli/tests/bug53503.phpt | 11 ++++--- ext/mysqlnd/mysqlnd_result.c | 1 + 5 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 ext/mysql/tests/bug53649.phpt diff --git a/NEWS b/NEWS index eb6609bec5..7c5cc199c4 100644 --- a/NEWS +++ b/NEWS @@ -45,7 +45,7 @@ - MySQL Improved extension: . Fixed bug #53503 (mysqli::query returns false after successful LOAD DATA - query). (Kalle) + query). (Kalle, Andrey) . Fixed bug #53425 (mysqli_real_connect() ignores client flags when built to call libmysql). (Kalle, tre-php-net at crushedhat dot com) . Fixed buggy counting of affected rows when using the text protocol. The diff --git a/ext/mysql/tests/bug53649.phpt b/ext/mysql/tests/bug53649.phpt new file mode 100644 index 0000000000..126f34b738 --- /dev/null +++ b/ext/mysql/tests/bug53649.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #53649 (mysql_query with "load data" unable to save result set) +--SKIPIF-- + +--FILE-- +errno, $link->error); + } + + if (!mysql_query("CREATE TABLE tlocaldata (dump1 INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine, $link)) { + printf("[003] [%d] %s\n", $link->errno, $link->error); + } + + file_put_contents('bug53649.data', "1\n2\n3\n"); + + mysql_query("SELECT 1 FROM DUAL", $link); + + if (!mysql_query("LOAD DATA LOCAL INFILE 'bug53649.data' INTO TABLE tlocaldata", $link)) { + echo "bug"; + } else { + echo "done"; + } + mysql_close($link); +?> +--CLEAN-- + +--EXPECT-- +done \ No newline at end of file diff --git a/ext/mysqli/mysqli_nonapi.c b/ext/mysqli/mysqli_nonapi.c index e9b6b4f27c..6de657c279 100644 --- a/ext/mysqli/mysqli_nonapi.c +++ b/ext/mysqli/mysqli_nonapi.c @@ -541,7 +541,7 @@ PHP_FUNCTION(mysqli_query) result = mysql_use_result(mysql->mysql); break; } - if (!result && mysql_errno(mysql->mysql)) { + if (!result) { php_mysqli_throw_sql_exception((char *)mysql_sqlstate(mysql->mysql), mysql_errno(mysql->mysql) TSRMLS_CC, "%s", mysql_error(mysql->mysql)); RETURN_FALSE; diff --git a/ext/mysqli/tests/bug53503.phpt b/ext/mysqli/tests/bug53503.phpt index 1a2b7ed71a..6b705524eb 100644 --- a/ext/mysqli/tests/bug53503.phpt +++ b/ext/mysqli/tests/bug53503.phpt @@ -21,13 +21,16 @@ require_once('skipifconnectfailure.inc'); printf("[003] [%d] %s\n", $link->errno, $link->error); } - file_put_contents('bug53503.data', 'jokijoki'); + file_put_contents('bug53503.data', "1\n2\n3\n"); - if (!$link->query("LOAD DATA LOCAL INFILE 'bug53503.data' REPLACE INTO TABLE tlocaldata (dump1)")) { + $link->query("SELECT 1 FROM DUAL"); + + if (!$link->query("LOAD DATA LOCAL INFILE 'bug53503.data' INTO TABLE tlocaldata")) { echo "bug"; } else { echo "done"; } + $link->close(); ?> --CLEAN-- query($link, 'DROP TABLE IF EXISTS tlocaldata')) { printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } -mysqli_close($link); +$link->close(); unlink('bug53503.data'); ?> diff --git a/ext/mysqlnd/mysqlnd_result.c b/ext/mysqlnd/mysqlnd_result.c index d1342e850d..2979e56667 100644 --- a/ext/mysqlnd/mysqlnd_result.c +++ b/ext/mysqlnd/mysqlnd_result.c @@ -431,6 +431,7 @@ mysqlnd_query_read_result_set_header(MYSQLND *conn, MYSQLND_STMT * s TSRMLS_DC) zend_bool is_warning; DBG_INF("LOAD DATA"); conn->last_query_type = QUERY_LOAD_LOCAL; + conn->field_count = 0; /* overwrite previous value, or the last value could be used and lead to bug#53503 */ CONN_SET_STATE(conn, CONN_SENDING_LOAD_DATA); ret = mysqlnd_handle_local_infile(conn, rset_header->info_or_local_file, &is_warning TSRMLS_CC); CONN_SET_STATE(conn, (ret == PASS || is_warning == TRUE)? CONN_READY:CONN_QUIT_SENT); -- 2.40.0