Skip to content

Commit 33349c4

Browse files
committed
Add new test
1 parent b168ae5 commit 33349c4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Confirm that PDO::ATTR_ERRMODE value should be restored whether PDO::lastInsertId() call succeeded or not.
3+
--SKIPIF--
4+
<?php require('skipif_mid-refactor.inc'); ?>
5+
--FILE--
6+
<?php
7+
require_once("MsCommon_mid-refactor.inc");
8+
9+
try {
10+
$conn = connect();
11+
12+
// create temporary tables
13+
createTable($conn, "table1", array(new columnMeta("int", "id", "IDENTITY(100,2)"), "val" => "int"));
14+
createTable($conn, "table2", array(new columnMeta("int", "id", "IDENTITY(200,2)"), "val" => "int"));
15+
createTable($conn, "table3", array("id" => "int", "val" => "int"));
16+
17+
insertRow($conn, "table1", array("val" => 1), "exec");
18+
insertRow($conn, "table2", array("val" => 2), "exec");
19+
$conn->lastInsertId();
20+
var_dump($conn->getAttribute(PDO::ATTR_ERRMODE));
21+
22+
insertRow($conn, "table2", array("val" => 3), "exec");
23+
insertRow($conn, "table1", array("val" => 4), "exec");
24+
$conn->lastInsertId();
25+
var_dump($conn->getAttribute(PDO::ATTR_ERRMODE));
26+
27+
// Should restore original value even if PDO::lastInsertId() failed.
28+
insertRow($conn, "table3", array("id" => 1, "val" => 1), "exec");
29+
$conn->lastInsertId();
30+
var_dump($conn->getAttribute(PDO::ATTR_ERRMODE));
31+
32+
dropTable($conn, "table1");
33+
dropTable($conn, "table2");
34+
dropTable($conn, "table3");
35+
unset($conn);
36+
} catch (PDOException $e) {
37+
var_dump($e);
38+
exit;
39+
}
40+
41+
42+
?>
43+
--EXPECT--
44+
int(2)
45+
int(2)
46+
int(2)

0 commit comments

Comments
 (0)