Skip to content

Commit 0a77904

Browse files
kamil-tekielaGirgias
authored andcommitted
Add test case for errorCode()
1 parent 3292b97 commit 0a77904

File tree

4 files changed

+50
-3
lines changed

4 files changed

+50
-3
lines changed

ext/pdo/pdo_stmt.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,9 @@ PHP_METHOD(PDOStatement, errorCode)
15291529
ZEND_PARSE_PARAMETERS_NONE();
15301530

15311531
PHP_STMT_GET_OBJ;
1532-
ZEND_ASSERT(stmt->error_code[0] != '\0');
1532+
if (stmt->error_code[0] == '\0') {
1533+
RETURN_NULL();
1534+
}
15331535

15341536
RETURN_STRING(stmt->error_code);
15351537
}

ext/pdo/pdo_stmt.stub.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function columnCount() {}
2424
/** @return bool|null */
2525
public function debugDumpParams() {}
2626

27-
/** @return string */
27+
/** @return string|null */
2828
public function errorCode() {}
2929

3030
/** @return array */

ext/pdo/pdo_stmt_arginfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 90e3fbe4a33c7613d279f2942dcd5dc403e68a28 */
2+
* Stub hash: 3bde9f58b85bc33ff6e4414b7802f42e10e4eab0 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDOStatement_bindColumn, 0, 0, 2)
55
ZEND_ARG_TYPE_MASK(0, column, MAY_BE_STRING|MAY_BE_LONG, NULL)

ext/pdo/tests/pdo_039.phpt

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
PDO Common: errorCode()
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('pdo')) die('skip');
6+
$dir = getenv('REDIR_TEST_DIR');
7+
if (false == $dir) die('skip no driver');
8+
require_once $dir . 'pdo_test.inc';
9+
PDOTest::skip();
10+
?>
11+
--FILE--
12+
<?php
13+
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
14+
15+
$dsn = getenv('PDOTEST_DSN');
16+
$user = getenv('PDOTEST_USER');
17+
$pass = getenv('PDOTEST_PASS');
18+
$attr = getenv('PDOTEST_ATTR');
19+
if (is_string($attr) && strlen($attr)) {
20+
$attr = unserialize($attr);
21+
} else {
22+
$attr = null;
23+
}
24+
25+
if ($user === false) $user = NULL;
26+
if ($pass === false) $pass = NULL;
27+
28+
$conn = new PDO($dsn, $user, $pass, $attr);
29+
30+
$query = 'SELECT 1';
31+
32+
var_dump($conn->errorCode());
33+
$stmt = $conn->prepare($query);
34+
var_dump($conn->errorCode());
35+
36+
var_dump($stmt->errorCode());
37+
$stmt->execute();
38+
var_dump($stmt->errorCode());
39+
40+
?>
41+
--EXPECT--
42+
NULL
43+
string(5) "00000"
44+
NULL
45+
string(5) "00000"

0 commit comments

Comments
 (0)