[php-src] master: Add test case for errorCode()
| From: | Kamil Tekiela via George Peter Banyard | Date: | Sun, 25 Apr 2021 14:57:42 +0000 |
| Subject: | [php-src] master: Add test case for errorCode() | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-115798@lists.php.net to get a copy of this message | ||
Author: Kamil Tekiela (kamil-tekiela)
Committer: George Peter Banyard (Girgias)
Date: 2021-04-25T15:57:43+01:00
Commit: https://github.com/php/php-src/commit/0a779040a023a205a62e40e8e8328c5edde00086
Raw diff: https://github.com/php/php-src/commit/0a779040a023a205a62e40e8e8328c5edde00086.diff
Add test case for errorCode()
Changed paths:
A ext/pdo/tests/pdo_039.phpt
M ext/pdo/pdo_stmt.c
M ext/pdo/pdo_stmt.stub.php
M ext/pdo/pdo_stmt_arginfo.h
Diff:
diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c
index 63fbd70c8613d..dd3fa4cacf56d 100644
--- a/ext/pdo/pdo_stmt.c
+++ b/ext/pdo/pdo_stmt.c
@@ -1529,7 +1529,9 @@ PHP_METHOD(PDOStatement, errorCode)
ZEND_PARSE_PARAMETERS_NONE();
PHP_STMT_GET_OBJ;
- ZEND_ASSERT(stmt->error_code[0] != '\0');
+ if (stmt->error_code[0] == '\0') {
+ RETURN_NULL();
+ }
RETURN_STRING(stmt->error_code);
}
diff --git a/ext/pdo/pdo_stmt.stub.php b/ext/pdo/pdo_stmt.stub.php
index 207bd3c2e25f6..3a873b307ebda 100644
--- a/ext/pdo/pdo_stmt.stub.php
+++ b/ext/pdo/pdo_stmt.stub.php
@@ -24,7 +24,7 @@ public function columnCount() {}
/** @return bool|null */
public function debugDumpParams() {}
- /** @return string */
+ /** @return string|null */
public function errorCode() {}
/** @return array */
diff --git a/ext/pdo/pdo_stmt_arginfo.h b/ext/pdo/pdo_stmt_arginfo.h
index a7cd771836159..cd3e0549b4527 100644
--- a/ext/pdo/pdo_stmt_arginfo.h
+++ b/ext/pdo/pdo_stmt_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 90e3fbe4a33c7613d279f2942dcd5dc403e68a28 */
+ * Stub hash: 3bde9f58b85bc33ff6e4414b7802f42e10e4eab0 */
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindColumn, 0, 0, 2)
ZEND_ARG_TYPE_MASK(0, column, MAY_BE_STRING|MAY_BE_LONG, NULL)
diff --git a/ext/pdo/tests/pdo_039.phpt b/ext/pdo/tests/pdo_039.phpt
new file mode 100644
index 0000000000000..68b5fff2db157
--- /dev/null
+++ b/ext/pdo/tests/pdo_039.phpt
@@ -0,0 +1,45 @@
+--TEST--
+PDO Common: errorCode()
+--SKIPIF--
+<?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='.__DIR__ .
'/../../pdo/tests/');
+
+$dsn = getenv('PDOTEST_DSN');
+$user = getenv('PDOTEST_USER');
+$pass = getenv('PDOTEST_PASS');
+$attr = getenv('PDOTEST_ATTR');
+if (is_string($attr) && strlen($attr)) {
+ $attr = unserialize($attr);
+} else {
+ $attr = null;
+}
+
+if ($user === false) $user = NULL;
+if ($pass === false) $pass = NULL;
+
+$conn = new PDO($dsn, $user, $pass, $attr);
+
+$query = 'SELECT 1';
+
+var_dump($conn->errorCode());
+$stmt = $conn->prepare($query);
+var_dump($conn->errorCode());
+
+var_dump($stmt->errorCode());
+$stmt->execute();
+var_dump($stmt->errorCode());
+
+?>
+--EXPECT--
+NULL
+string(5) "00000"
+NULL
+string(5) "00000"