]> granicus.if.org Git - php/commitdiff
Proper fix for
authorAndrey Hristov <andrey@php.net>
Fri, 7 Jan 2011 14:22:30 +0000 (14:22 +0000)
committerAndrey Hristov <andrey@php.net>
Fri, 7 Jan 2011 14:22:30 +0000 (14:22 +0000)
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.

ext/mysql/tests/bug53649.phpt [new file with mode: 0644]
ext/mysqli/mysqli_nonapi.c
ext/mysqli/tests/bug53503.phpt
ext/mysqlnd/mysqlnd_result.c

diff --git a/ext/mysql/tests/bug53649.phpt b/ext/mysql/tests/bug53649.phpt
new file mode 100644 (file)
index 0000000..126f34b
--- /dev/null
@@ -0,0 +1,53 @@
+--TEST--\r
+Bug #53649 (mysql_query with "load data" unable to save result set)\r
+--SKIPIF--\r
+<?php\r
+require_once('skipif.inc');\r
+require_once('skipifconnectfailure.inc');\r
+?>\r
+--FILE--\r
+<?php\r
+       require_once("connect.inc");\r
+\r
+       if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {\r
+               printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());\r
+       }\r
+\r
+       if (!mysql_query("DROP TABLE IF EXISTS tlocaldata", $link)) {\r
+               printf("[002] [%d] %s\n", $link->errno, $link->error);\r
+       }\r
+\r
+       if (!mysql_query("CREATE TABLE tlocaldata (dump1 INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine, $link)) {\r
+               printf("[003] [%d] %s\n", $link->errno, $link->error);\r
+       }\r
+\r
+       file_put_contents('bug53649.data', "1\n2\n3\n");\r
+\r
+       mysql_query("SELECT 1 FROM DUAL", $link);\r
+\r
+       if (!mysql_query("LOAD DATA LOCAL INFILE 'bug53649.data' INTO TABLE tlocaldata", $link)) {\r
+               echo "bug";\r
+       } else {\r
+               echo "done";\r
+       }\r
+       mysql_close($link);\r
+?>\r
+--CLEAN--\r
+<?php\r
+require_once('connect.inc');\r
+\r
+if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {\r
+       printf("[clean] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",\r
+               $host, $user, $db, $port, $socket);\r
+}\r
+\r
+if (!mysql_query($link, 'DROP TABLE IF EXISTS tlocaldata', $link)) {\r
+       printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));\r
+}\r
+\r
+mysql_close($link);\r
+\r
+unlink('bug53649.data');\r
+?>\r
+--EXPECT--\r
+done
\ No newline at end of file
index a896d49fabec57182fc078ad5d910bfbe9bcdae4..04755df22492583a26a2fe4affeba40fa288d8eb 100644 (file)
@@ -529,7 +529,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;
index 1a2b7ed71a6ecedfc509147d7f5ad69cc4963f62..6b705524ebad5076af7fa4f73b653d2f61c5cc1a 100644 (file)
@@ -21,13 +21,16 @@ require_once('skipifconnectfailure.inc');
                printf("[003] [%d] %s\n", $link->errno, $link->error);\r
        }\r
 \r
-       file_put_contents('bug53503.data', 'jokijoki');\r
+       file_put_contents('bug53503.data', "1\n2\n3\n");\r
 \r
-       if (!$link->query("LOAD DATA LOCAL INFILE 'bug53503.data' REPLACE INTO TABLE tlocaldata (dump1)")) {\r
+       $link->query("SELECT 1 FROM DUAL");\r
+\r
+       if (!$link->query("LOAD DATA LOCAL INFILE 'bug53503.data' INTO TABLE tlocaldata")) {\r
                echo "bug";\r
        } else {\r
                echo "done";\r
        }\r
+       $link->close();\r
 ?>\r
 --CLEAN--\r
 <?php\r
@@ -38,11 +41,11 @@ if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
                $host, $user, $db, $port, $socket);\r
 }\r
 \r
-if (!mysqli_query($link, 'DROP TABLE IF EXISTS tlocaldata')) {\r
+if (!$link->query($link, 'DROP TABLE IF EXISTS tlocaldata')) {\r
        printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));\r
 }\r
 \r
-mysqli_close($link);\r
+$link->close();\r
 \r
 unlink('bug53503.data');\r
 ?>\r
index 7bed061d9e174b711f4f5c6e17605966670abef8..68331aa2ecacd508e0fd9ad4d08e1ccd40a82d45 100644 (file)
@@ -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);