Skip to content

Commit 56c1165

Browse files
committed
Add a test for repeated transaction commands
1 parent 816e0b5 commit 56c1165

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/WP_SQLite_Driver_Tests.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,6 +2490,28 @@ public function testStartTransactionCommand() {
24902490
$this->assertCount( 0, $this->engine->get_query_results() );
24912491
}
24922492

2493+
public function testRepeatedTransactionCommands(): void {
2494+
$this->assertQuery( 'CREATE TABLE t (id INT)' );
2495+
2496+
// 1st BEGIN starts a transaction.
2497+
$this->assertQuery( 'BEGIN' );
2498+
$this->assertQuery( 'INSERT INTO t (id) VALUES (1);' );
2499+
2500+
// 2nd BEGIN commits the previous transaction and starts a new one.
2501+
$this->assertQuery( 'BEGIN' );
2502+
$this->assertQuery( 'INSERT INTO t (id) VALUES (2);' );
2503+
2504+
// ROLLBACK rolls back the 2nd transaction.
2505+
$this->assertQuery( 'ROLLBACK' );
2506+
$results = $this->assertQuery( 'SELECT * FROM t;' );
2507+
$this->assertEquals( array( (object) array( 'id' => '1' ) ), $results );
2508+
2509+
// Repeated ROLLBACK should do nothing.
2510+
$this->assertQuery( 'ROLLBACK' );
2511+
$results = $this->assertQuery( 'SELECT * FROM t;' );
2512+
$this->assertEquals( array( (object) array( 'id' => '1' ) ), $results );
2513+
}
2514+
24932515
public function testCount() {
24942516
$this->assertQuery( "INSERT INTO _options (option_name) VALUES ('first');" );
24952517
$this->assertQuery( "INSERT INTO _options (option_name) VALUES ('second');" );

0 commit comments

Comments
 (0)