com php-src: Fixed bug #79872 by improving error message: NEWS ext/pdo_mysql/mysql_driver.c ext/pdo_mysql/tests/bug 79872.phpt
| From: | Nikita Popov | Date: | Thu, 10 Dec 2020 10:46:29 +0000 |
| Subject: | com php-src: Fixed bug #79872 by improving error message: NEWS ext/pdo_mysql/mysql_driver.c ext/pdo_mysql/tests/bug 79872.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114402@lists.php.net to get a copy of this message | ||
Commit: 288581fadef58363dac4fc72ded0fae830bf603c
Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 10 Dec 2020 11:46:29 +0100
Parents: d63aedd173fbb8b3399cff4b991f8a343dd0f331
Branches: PHP-8.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=288581fadef58363dac4fc72ded0fae830bf603c
Log:
Fixed bug #79872 by improving error message
The actual behavior here is correct, but the previous error
message was misleading, as neither fetchAll() nor buffered queries
would help in this situation. Instead it is necessary to consume
all rowsets, which can be done by either unsetting the statement
or calling closeCursor().
Bugs:
https://bugs.php.net/79872
Changed paths:
M NEWS
M ext/pdo_mysql/mysql_driver.c
A ext/pdo_mysql/tests/bug79872.phpt
Diff:
diff --git a/NEWS b/NEWS
index 5178fb162fa..0a91136d763 100644
--- a/NEWS
+++ b/NEWS
@@ -51,6 +51,7 @@ PHP NEWS
query error). (Nikita)
. Fixed bug #76815 (PDOStatement cannot be GCed/closeCursor-ed when a
PROCEDURE resultset SIGNAL). (Nikita)
+ . Fixed bug #79872 (Can't execute query with pending result sets). (Nikita)
- Phar:
. Fixed bug #73809 (Phar Zip parse crash - mmap fail). (cmb)
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c
index 764c453438e..90bc7792d5f 100644
--- a/ext/pdo_mysql/mysql_driver.c
+++ b/ext/pdo_mysql/mysql_driver.c
@@ -73,12 +73,20 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
if (einfo->errcode) {
if (einfo->errcode == 2014) {
- einfo->errmsg = pestrdup(
- "Cannot execute queries while other unbuffered queries are active. "
- "Consider using PDOStatement::fetchAll(). Alternatively, if your code "
- "is only ever going to run against mysql, you may enable query "
- "buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.",
- dbh->is_persistent);
+ if (mysql_more_results(H->server)) {
+ einfo->errmsg = pestrdup(
+ "Cannot execute queries while there are pending result sets. "
+ "Consider unsetting the previous PDOStatement or calling "
+ "PDOStatement::closeCursor()",
+ dbh->is_persistent);
+ } else {
+ einfo->errmsg = pestrdup(
+ "Cannot execute queries while other unbuffered queries are active. "
+ "Consider using PDOStatement::fetchAll(). Alternatively, if your code "
+ "is only ever going to run against mysql, you may enable query "
+ "buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.",
+ dbh->is_persistent);
+ }
} else if (einfo->errcode == 2057) {
einfo->errmsg = pestrdup(
"A stored procedure returning result sets of different size was called. "
diff --git a/ext/pdo_mysql/tests/bug79872.phpt b/ext/pdo_mysql/tests/bug79872.phpt
new file mode 100644
index 00000000000..0d1ecaf2d31
--- /dev/null
+++ b/ext/pdo_mysql/tests/bug79872.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Bug #79872: Can't execute query with pending result sets
+--SKIPIF--
+<?php
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+MySQLPDOTest::skip();
+?>
+--FILE--
+<?php
+require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
+
+$db = MySQLPDOTest::factory();
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+
+$stmt = $db->prepare('SET @foo = 1; SET @bar = 2;');
+$stmt->execute();
+try {
+ var_dump($db->query('SELECT @foo')->fetchAll());
+} catch (PDOException $e) {
+ echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+SQLSTATE[HY000]: General error: 2014 Cannot execute queries while there are pending result sets.
Consider unsetting the previous PDOStatement or calling PDOStatement::closeCursor()