com php-src: Fix bug #64172: ext/pdo/pdo_dbh.c ext/pdo/te sts/bug_64172.phpt ext/pdo_mysql/tests/pdo_ mysql_stmt_errorinfo.phpt
| From: | Stanislav Malyshev | Date: | Mon, 19 Oct 2015 00:03:39 +0000 |
| Subject: | com php-src: Fix bug #64172: ext/pdo/pdo_dbh.c ext/pdo/te sts/bug_64172.phpt ext/pdo_mysql/tests/pdo_ mysql_stmt_errorinfo.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89453@lists.php.net to get a copy of this message | ||
Commit: 307c1f6bf0e8e3c97416b2a22ed54dd4546ea689
Author: Daniel Persson <daniel.persson@textalk.se> Sat, 26 Sep 2015 21:48:18 +0200
Committer: Stanislav Malyshev <stas@php.net> Sun, 18 Oct 2015 17:03:39 -0700
Parents: c7c6df6cec04b3b46160fd726c2af698bbdf4dc9
Branches: PHP-7.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=307c1f6bf0e8e3c97416b2a22ed54dd4546ea689
Log:
Fix bug #64172
Check if the SQLSTATE error code is equal to PDO_ERR_NONE before we ask the driver.
And if no error is reported skip the extra call to the driver.
Bugs:
https://bugs.php.net/64172
Changed paths:
M ext/pdo/pdo_dbh.c
A ext/pdo/tests/bug_64172.phpt
M ext/pdo_mysql/tests/pdo_mysql_stmt_errorinfo.phpt
Diff:
diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c
index 1607792..ddf3b78 100644
--- a/ext/pdo/pdo_dbh.c
+++ b/ext/pdo/pdo_dbh.c
@@ -1016,14 +1016,17 @@ static PHP_METHOD(PDO, errorInfo)
if (dbh->query_stmt) {
add_next_index_string(return_value, dbh->query_stmt->error_code);
+ if(!strncmp(dbh->query_stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto
fill_array;
} else {
add_next_index_string(return_value, dbh->error_code);
+ if(!strncmp(dbh->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) goto fill_array;
}
if (dbh->methods->fetch_err) {
dbh->methods->fetch_err(dbh, dbh->query_stmt, return_value);
}
+fill_array:
/**
* In order to be consistent, we have to make sure we add the good amount
* of nulls depending on the current number of elements. We make a simple
diff --git a/ext/pdo/tests/bug_64172.phpt b/ext/pdo/tests/bug_64172.phpt
new file mode 100644
index 0000000..e8949fe
--- /dev/null
+++ b/ext/pdo/tests/bug_64172.phpt
@@ -0,0 +1,84 @@
+--TEST--
+PDO Common: Bug #64172 errorInfo is not properly cleaned up
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo')) die('skip');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false)
putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../.../pdo/tests/');
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+
+$db = PDOTest::factory();
+
+@$db->exec("DROP TABLE test");
+$db->exec("CREATE TABLE test (x int)");
+$db->exec("INSERT INTO test VALUES (1)");
+
+echo "===FAIL===\n";
+$db->query('SELECT * FROM bad_table');
+echo "\n";
+echo "===TEST===\n";
+var_dump(is_string($db->errorInfo()[0])) . "\n";
+var_dump(is_int($db->errorInfo()[1])) . "\n";
+var_dump(is_string($db->errorInfo()[2])) . "\n";
+echo "===GOOD===\n";
+$stmt = $db->query('SELECT * FROM test');
+$stmt->fetchAll();
+$stmt = null;
+var_dump($db->errorInfo());
+
+echo "===FAIL===\n";
+$db->exec("INSERT INTO bad_table VALUES(1)");
+echo "\n";
+echo "===TEST===\n";
+var_dump(is_string($db->errorInfo()[0])) . "\n";
+var_dump(is_int($db->errorInfo()[1])) . "\n";
+var_dump(is_string($db->errorInfo()[2])) . "\n";
+echo "===GOOD===\n";
+$db->exec("INSERT INTO test VALUES (2)");
+var_dump($db->errorInfo());
+
+$db->exec("DROP TABLE test");
+?>
+===DONE===
+--EXPECTF--
+===FAIL===
+
+Warning: PDO::query(): SQLSTATE[%s]: %s
+%A
+===TEST===
+bool(true)
+bool(true)
+bool(true)
+===GOOD===
+array(3) {
+ [0]=>
+ string(5) "00000"
+ [1]=>
+ NULL
+ [2]=>
+ NULL
+}
+===FAIL===
+
+Warning: PDO::exec(): SQLSTATE[%s]: %s
+%A
+===TEST===
+bool(true)
+bool(true)
+bool(true)
+===GOOD===
+array(3) {
+ [0]=>
+ string(5) "00000"
+ [1]=>
+ NULL
+ [2]=>
+ NULL
+}
+===DONE===
\ No newline at end of file
diff --git a/ext/pdo_mysql/tests/pdo_mysql_stmt_errorinfo.phpt
b/ext/pdo_mysql/tests/pdo_mysql_stmt_errorinfo.phpt
index d5a3489..9028f0b 100644
--- a/ext/pdo_mysql/tests/pdo_mysql_stmt_errorinfo.phpt
+++ b/ext/pdo_mysql/tests/pdo_mysql_stmt_errorinfo.phpt
@@ -129,8 +129,8 @@ array(3) {
[0]=>
%unicode|string%(5) "00000"
[1]=>
- int(1146)
+ NULL
[2]=>
- %unicode|string%(%d) "Table '%s.ihopeitdoesnotexist' doesn't exist"
+ NULL
}
done!