Add test case for errorCode()

This commit is contained in:
Kamil Tekiela 2021-04-25 14:50:59 +01:00 committed by George Peter Banyard
parent 3292b9761a
commit 0a779040a0
4 changed files with 50 additions and 3 deletions

View file

@ -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);
}

View file

@ -24,7 +24,7 @@ class PDOStatement implements IteratorAggregate
/** @return bool|null */
public function debugDumpParams() {}
/** @return string */
/** @return string|null */
public function errorCode() {}
/** @return array */

View file

@ -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)

View file

@ -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"