Browse Source

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.
pull/12/head
Andrey Hristov 15 years ago
parent
commit
eaaef0d870
  1. 2
      NEWS
  2. 53
      ext/mysql/tests/bug53649.phpt
  3. 2
      ext/mysqli/mysqli_nonapi.c
  4. 11
      ext/mysqli/tests/bug53503.phpt
  5. 1
      ext/mysqlnd/mysqlnd_result.c

2
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

53
ext/mysql/tests/bug53649.phpt

@ -0,0 +1,53 @@
--TEST--
Bug #53649 (mysql_query with "load data" unable to save result set)
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
require_once("connect.inc");
if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
if (!mysql_query("DROP TABLE IF EXISTS tlocaldata", $link)) {
printf("[002] [%d] %s\n", $link->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--
<?php
require_once('connect.inc');
if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
printf("[clean] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);
}
if (!mysql_query($link, 'DROP TABLE IF EXISTS tlocaldata', $link)) {
printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysql_close($link);
unlink('bug53649.data');
?>
--EXPECT--
done

2
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;

11
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--
<?php
@ -38,11 +41,11 @@ if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
$host, $user, $db, $port, $socket);
}
if (!mysqli_query($link, 'DROP TABLE IF EXISTS tlocaldata')) {
if (!$link->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');
?>

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

Loading…
Cancel
Save