From 8283f9da9995eccd7bad2c378490e486737f4d26 Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 25 May 2022 11:13:49 +0800 Subject: [PATCH 1/9] Fix PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect --- ext/pdo/pdo_stmt.c | 6 +++-- ext/pdo/tests/gh8626.phpt | 52 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 ext/pdo/tests/gh8626.phpt diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index ad7df5c241e37..e88a37465699f 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -1617,8 +1617,10 @@ PHP_METHOD(PDOStatement, errorInfo) array_init(return_value); add_next_index_string(return_value, stmt->error_code); - if (stmt->dbh->methods->fetch_err) { - stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value); + if (strncmp(stmt->error_code, PDO_ERR_NONE, sizeof(PDO_ERR_NONE))) { + if (stmt->dbh->methods->fetch_err) { + stmt->dbh->methods->fetch_err(stmt->dbh, stmt, return_value); + } } error_count = zend_hash_num_elements(Z_ARRVAL_P(return_value)); diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt new file mode 100644 index 0000000000000..b6a823ad6a333 --- /dev/null +++ b/ext/pdo/tests/gh8626.phpt @@ -0,0 +1,52 @@ +--TEST-- +GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect +--SKIPIF-- + +--FILE-- +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); + +@$db->exec("DROP TABLE test"); +$db->exec("CREATE TABLE test (x int)"); + +$stmt = $db->prepare('INSERT INTO test VALUES(?)'); + +// fail +var_dump($stmt->execute([PHP_INT_MIN]), $stmt->errorCode(), $stmt->errorInfo()); + +// success +var_dump($stmt->execute([1]), $stmt->errorCode(), $stmt->errorInfo()); +?> +===DONE=== +--EXPECTF-- +bool(false) +string(%d) "%s" +array(3) { + [0]=> + string(%d) "%s" + [1]=> + int(%d) + [2]=> + string(%d) "%s" +} +bool(true) +string(5) "00000" +array(3) { + [0]=> + string(5) "00000" + [1]=> + NULL + [2]=> + NULL +} +===DONE=== From e1ba1b232f258ba5d314736a32193c3c7f0f1787 Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 25 May 2022 16:52:02 +0800 Subject: [PATCH 2/9] Fix other driver test --- ext/pdo/tests/gh8626.phpt | 1 + 1 file changed, 1 insertion(+) diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt index b6a823ad6a333..15ffb8458b872 100644 --- a/ext/pdo/tests/gh8626.phpt +++ b/ext/pdo/tests/gh8626.phpt @@ -5,6 +5,7 @@ GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() if (!extension_loaded('pdo')) die('skip'); $dir = getenv('REDIR_TEST_DIR'); if (false == $dir) die('skip no driver'); +if (!strncasecmp(getenv('PDOTEST_DSN'), 'mysql', strlen('mysql'))) die('skip not relevant for mysql driver'); require_once $dir . 'pdo_test.inc'; PDOTest::skip(); ?> From 4a0025534a41c6e7f7a264b84cd7c884e0337a8f Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 25 May 2022 17:27:15 +0800 Subject: [PATCH 3/9] Fix test --- ext/pdo_pgsql/tests/bug62593.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/pdo_pgsql/tests/bug62593.phpt b/ext/pdo_pgsql/tests/bug62593.phpt index 598307a652105..998ce7f37ab9c 100644 --- a/ext/pdo_pgsql/tests/bug62593.phpt +++ b/ext/pdo_pgsql/tests/bug62593.phpt @@ -51,7 +51,7 @@ $expect = 'No errors found'; foreach ($errors as $error) { - if (strpos('Invalid text representation', $error[2]) !== false) + if (null !== $error[2] && strpos('Invalid text representation', $error[2]) !== false) { $expect = 'Invalid boolean found'; } From c402f11fa60d9cde93894705cb21f406e0951d3d Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 25 May 2022 18:09:26 +0800 Subject: [PATCH 4/9] Fix test --- ext/pdo/tests/gh8626.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt index 15ffb8458b872..e1c7720ff9b97 100644 --- a/ext/pdo/tests/gh8626.phpt +++ b/ext/pdo/tests/gh8626.phpt @@ -2,10 +2,10 @@ GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect --SKIPIF-- From 46d4402749c6842a85dd1eaea16a29149d8319d7 Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 25 May 2022 18:54:54 +0800 Subject: [PATCH 5/9] Fix I386 test --- ext/pdo/tests/gh8626.phpt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt index e1c7720ff9b97..a7b011e1833c6 100644 --- a/ext/pdo/tests/gh8626.phpt +++ b/ext/pdo/tests/gh8626.phpt @@ -17,8 +17,9 @@ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; $db = PDOTest::factory(); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); -@$db->exec("DROP TABLE test"); -$db->exec("CREATE TABLE test (x int)"); +$db->exec("SET SESSION sql_mode=CONCAT((select @@sql_mode),',STRICT_TRANS_TABLES')"); +@$db->exec('DROP TABLE test'); +$db->exec('CREATE TABLE test (x int)'); $stmt = $db->prepare('INSERT INTO test VALUES(?)'); From b00dabf20a9d726809bf8db88c2a4cc32bfd6d76 Mon Sep 17 00:00:00 2001 From: Yurun Date: Thu, 26 May 2022 11:22:18 +0800 Subject: [PATCH 6/9] Support pgsql, sqlite driver test --- ext/pdo/tests/gh8626.phpt | 50 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt index a7b011e1833c6..e6842cc48d4c2 100644 --- a/ext/pdo/tests/gh8626.phpt +++ b/ext/pdo/tests/gh8626.phpt @@ -2,10 +2,13 @@ GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() information is incorrect --SKIPIF-- @@ -17,38 +20,39 @@ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; $db = PDOTest::factory(); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT); -$db->exec("SET SESSION sql_mode=CONCAT((select @@sql_mode),',STRICT_TRANS_TABLES')"); -@$db->exec('DROP TABLE test'); -$db->exec('CREATE TABLE test (x int)'); +$db->exec('DROP TABLE test'); +$db->exec('CREATE TABLE test (x int NOT NULL)'); $stmt = $db->prepare('INSERT INTO test VALUES(?)'); // fail -var_dump($stmt->execute([PHP_INT_MIN]), $stmt->errorCode(), $stmt->errorInfo()); +var_dump($stmt->execute([null]), $stmt->errorCode(), $stmt->errorInfo()); + +$stmt->closeCursor(); // success var_dump($stmt->execute([1]), $stmt->errorCode(), $stmt->errorInfo()); ?> ===DONE=== ---EXPECTF-- -bool(false) -string(%d) "%s" -array(3) { - [0]=> - string(%d) "%s" - [1]=> - int(%d) - [2]=> - string(%d) "%s" +--EXPECTREGEX-- +bool\(false\) +string\(\d+\) "[^"]+" +array\(3\) { + \[0\]=> + string\(\d+\) "[^"]+" + \[1\]=> + int\(\d+\) + \[2\]=> + string\(\d+\) "[^"]+((.+".+)*[^"]+)?" } -bool(true) -string(5) "00000" -array(3) { - [0]=> - string(5) "00000" - [1]=> +bool\(true\) +string\(5\) "00000" +array\(3\) { + \[0\]=> + string\(5\) "00000" + \[1\]=> NULL - [2]=> + \[2\]=> NULL } ===DONE=== From d0be22e21955c3e26f204960ee6e88721c4dccf7 Mon Sep 17 00:00:00 2001 From: Yurun Date: Thu, 26 May 2022 12:23:21 +0800 Subject: [PATCH 7/9] Fix --- ext/pdo/tests/gh8626.phpt | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt index e6842cc48d4c2..0f9d1614c5dcd 100644 --- a/ext/pdo/tests/gh8626.phpt +++ b/ext/pdo/tests/gh8626.phpt @@ -34,25 +34,25 @@ $stmt->closeCursor(); var_dump($stmt->execute([1]), $stmt->errorCode(), $stmt->errorInfo()); ?> ===DONE=== ---EXPECTREGEX-- -bool\(false\) -string\(\d+\) "[^"]+" -array\(3\) { - \[0\]=> - string\(\d+\) "[^"]+" - \[1\]=> - int\(\d+\) - \[2\]=> - string\(\d+\) "[^"]+((.+".+)*[^"]+)?" +--EXPECTF-- +bool(false) +string(%d) "%s" +array(3) { + [0]=> + string(%d) "%s" + [1]=> + int(%d) + [2]=> + string(%d) "%s%w%S" } -bool\(true\) -string\(5\) "00000" -array\(3\) { - \[0\]=> - string\(5\) "00000" - \[1\]=> +bool(true) +string(5) "00000" +array(3) { + [0]=> + string(5) "00000" + [1]=> NULL - \[2\]=> + [2]=> NULL } ===DONE=== From 1810d478d7861a15dd23b26d2e6ce2f1d4ed2082 Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 1 Jun 2022 09:13:51 +0800 Subject: [PATCH 8/9] remove skip --- ext/pdo/tests/gh8626.phpt | 3 --- 1 file changed, 3 deletions(-) diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt index 0f9d1614c5dcd..2b3fe6efb80ec 100644 --- a/ext/pdo/tests/gh8626.phpt +++ b/ext/pdo/tests/gh8626.phpt @@ -6,9 +6,6 @@ if (!extension_loaded('pdo')) die('skip'); $dir = getenv('REDIR_TEST_DIR'); if (false == $dir) die('skip no driver'); $driver = substr(getenv('PDOTEST_DSN'), 0, strpos(getenv('PDOTEST_DSN'), ':')); -if (!in_array($driver, array('mysql', 'pgsql', 'sqlite'))) { - die('skip not supported'); -} require_once $dir . 'pdo_test.inc'; PDOTest::skip(); ?> From 0b7427d7a1b953eb3cdbaa33da67bd91f17adf25 Mon Sep 17 00:00:00 2001 From: Yurun Date: Wed, 1 Jun 2022 11:19:55 +0800 Subject: [PATCH 9/9] Fix odbc test --- ext/pdo/tests/gh8626.phpt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ext/pdo/tests/gh8626.phpt b/ext/pdo/tests/gh8626.phpt index 2b3fe6efb80ec..54b95fbe97b73 100644 --- a/ext/pdo/tests/gh8626.phpt +++ b/ext/pdo/tests/gh8626.phpt @@ -5,7 +5,6 @@ GH-8626: PDOStatement->execute() failed, then execute successfully, errorInfo() if (!extension_loaded('pdo')) die('skip'); $dir = getenv('REDIR_TEST_DIR'); if (false == $dir) die('skip no driver'); -$driver = substr(getenv('PDOTEST_DSN'), 0, strpos(getenv('PDOTEST_DSN'), ':')); require_once $dir . 'pdo_test.inc'; PDOTest::skip(); ?> @@ -23,12 +22,22 @@ $db->exec('CREATE TABLE test (x int NOT NULL)'); $stmt = $db->prepare('INSERT INTO test VALUES(?)'); // fail -var_dump($stmt->execute([null]), $stmt->errorCode(), $stmt->errorInfo()); +var_dump($stmt->execute([null]), $stmt->errorCode()); +$errorInfo = $stmt->errorInfo(); +if (isset($errorInfo[3])) { + unset($errorInfo[3]); // odbc +} +var_dump($errorInfo); -$stmt->closeCursor(); +$stmt->closeCursor(); // sqlite // success -var_dump($stmt->execute([1]), $stmt->errorCode(), $stmt->errorInfo()); +var_dump($stmt->execute([1]), $stmt->errorCode()); +$errorInfo = $stmt->errorInfo(); +if (isset($errorInfo[3])) { + unset($errorInfo[3]); // odbc +} +var_dump($errorInfo); ?> ===DONE=== --EXPECTF--