Skip to content

Commit 9d55f8f

Browse files
committed
Add some tests for mixing transaction APIs and queries
1 parent 3a4cf02 commit 9d55f8f

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

ext/pdo_mysql/tests/pdo_mysql_inTransaction.phpt

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ const BEGIN = ['BEGIN', 'START TRANSACTION'];
1414
const END = ['COMMIT', 'ROLLBACK'];
1515

1616
$db = MySQLPDOTest::factory();
17-
// $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // mysql does not support
18-
for ($b = 0; $b < count(BEGIN); $b++) {
19-
for ($e = 0; $e < count(END); $e++) {
17+
// $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // mysql does not support
18+
foreach (BEGIN as $begin) {
19+
foreach (END as $end) {
2020
foreach (['exec', 'query', 'execute'] as $w) {
21-
foreach ([BEGIN[$b], END[$e]] as $command) {
21+
foreach ([$begin, $end] as $command) {
2222
switch ($w) {
2323
case 'exec':
2424
$db->exec($command);
@@ -40,6 +40,24 @@ for ($b = 0; $b < count(BEGIN); $b++) {
4040
}
4141
echo "\n";
4242

43+
// Mixing PDO transaction API and explicit queries.
44+
foreach (END as $end) {
45+
$db->beginTransaction();
46+
var_dump($db->inTransaction());
47+
$db->exec($end);
48+
var_dump($db->inTransaction());
49+
}
50+
51+
$db->exec('START TRANSACTION');
52+
var_dump($db->inTransaction());
53+
$db->rollBack();
54+
var_dump($db->inTransaction());
55+
$db->exec('START TRANSACTION');
56+
var_dump($db->inTransaction());
57+
$db->commit();
58+
var_dump($db->inTransaction());
59+
echo "\n";
60+
4361
// DDL query causes an implicit commit.
4462
$db->beginTransaction();
4563
var_dump($db->inTransaction());
@@ -50,6 +68,7 @@ var_dump($db->inTransaction());
5068
$db->beginTransaction();
5169
var_dump($db->inTransaction());
5270
$db->commit();
71+
var_dump($db->inTransaction());
5372

5473
?>
5574
--EXPECT--
@@ -81,3 +100,13 @@ bool(false)
81100
bool(true)
82101
bool(false)
83102
bool(true)
103+
bool(false)
104+
bool(true)
105+
bool(false)
106+
bool(true)
107+
bool(false)
108+
109+
bool(true)
110+
bool(false)
111+
bool(true)
112+
bool(false)

0 commit comments

Comments
 (0)