andrey Fri, 07 Jan 2011 14:22:30 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=307223
Log:
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.
Bugs: http://bugs.php.net/53503 (Closed) mysqli::query returns false after
successful LOAD DATA query
http://bugs.php.net/56349 (error getting bug information)
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
A php/php-src/branches/PHP_5_3/ext/mysql/tests/bug53649.phpt
U php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c
U php/php-src/branches/PHP_5_3/ext/mysqli/tests/bug53503.phpt
U php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c
A php/php-src/trunk/ext/mysql/tests/bug53649.phpt
U php/php-src/trunk/ext/mysqli/mysqli_nonapi.c
U php/php-src/trunk/ext/mysqli/tests/bug53503.phpt
U php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2011-01-07 13:13:46 UTC (rev 307222)
+++ php/php-src/branches/PHP_5_3/NEWS 2011-01-07 14:22:30 UTC (rev 307223)
@@ -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
Added: php/php-src/branches/PHP_5_3/ext/mysql/tests/bug53649.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysql/tests/bug53649.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/mysql/tests/bug53649.phpt 2011-01-07 14:22:30 UTC (rev 307223)
@@ -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
\ No newline at end of file
Modified: php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c 2011-01-07 13:13:46 UTC (rev 307222)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/mysqli_nonapi.c 2011-01-07 14:22:30 UTC (rev 307223)
@@ -541,7 +541,7 @@
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;
Modified: php/php-src/branches/PHP_5_3/ext/mysqli/tests/bug53503.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqli/tests/bug53503.phpt 2011-01-07 13:13:46 UTC (rev 307222)
+++ php/php-src/branches/PHP_5_3/ext/mysqli/tests/bug53503.phpt 2011-01-07 14:22:30 UTC (rev 307223)
@@ -21,13 +21,16 @@
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 @@
$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');
?>
Modified: php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c 2011-01-07 13:13:46 UTC (rev 307222)
+++ php/php-src/branches/PHP_5_3/ext/mysqlnd/mysqlnd_result.c 2011-01-07 14:22:30 UTC (rev 307223)
@@ -431,6 +431,7 @@
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);
Added: php/php-src/trunk/ext/mysql/tests/bug53649.phpt
===================================================================
--- php/php-src/trunk/ext/mysql/tests/bug53649.phpt (rev 0)
+++ php/php-src/trunk/ext/mysql/tests/bug53649.phpt 2011-01-07 14:22:30 UTC (rev 307223)
@@ -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
\ No newline at end of file
Modified: php/php-src/trunk/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_nonapi.c 2011-01-07 13:13:46 UTC (rev 307222)
+++ php/php-src/trunk/ext/mysqli/mysqli_nonapi.c 2011-01-07 14:22:30 UTC (rev 307223)
@@ -529,7 +529,7 @@
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;
Modified: php/php-src/trunk/ext/mysqli/tests/bug53503.phpt
===================================================================
--- php/php-src/trunk/ext/mysqli/tests/bug53503.phpt 2011-01-07 13:13:46 UTC (rev 307222)
+++ php/php-src/trunk/ext/mysqli/tests/bug53503.phpt 2011-01-07 14:22:30 UTC (rev 307223)
@@ -21,13 +21,16 @@
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 @@
$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');
?>
Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c 2011-01-07 13:13:46 UTC (rev 307222)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_result.c 2011-01-07 14:22:30 UTC (rev 307223)
@@ -431,6 +431,7 @@
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);
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php