@@ -6294,4 +6294,38 @@ public function testLockTemporaryTables(): void {
62946294 $ this ->assertQuery ( 'LOCK TABLES t1 READ, t2 READ, t3 WRITE ' );
62956295 $ this ->assertQuery ( 'UNLOCK TABLES ' );
62966296 }
6297+
6298+ public function testTransactionSavepoints (): void {
6299+ $ this ->assertQuery ( 'CREATE TABLE t (id INT) ' );
6300+
6301+ $ this ->assertQuery ( 'BEGIN ' );
6302+ $ this ->assertQuery ( 'INSERT INTO t (id) VALUES (1) ' );
6303+ $ result = $ this ->assertQuery ( 'SELECT * FROM t ' );
6304+ $ this ->assertSame ( array ( '1 ' ), (array ) array_column ( $ result , 'id ' ) );
6305+
6306+ $ this ->assertQuery ( 'SAVEPOINT sp1 ' );
6307+ $ this ->assertQuery ( 'INSERT INTO t (id) VALUES (2) ' );
6308+ $ result = $ this ->assertQuery ( 'SELECT * FROM t ' );
6309+ $ this ->assertSame ( array ( '1 ' , '2 ' ), (array ) array_column ( $ result , 'id ' ) );
6310+
6311+ $ this ->assertQuery ( 'SAVEPOINT sp2 ' );
6312+ $ this ->assertQuery ( 'INSERT INTO t (id) VALUES (3) ' );
6313+ $ result = $ this ->assertQuery ( 'SELECT * FROM t ' );
6314+ $ this ->assertSame ( array ( '1 ' , '2 ' , '3 ' ), (array ) array_column ( $ result , 'id ' ) );
6315+
6316+ $ this ->assertQuery ( 'ROLLBACK TO SAVEPOINT sp1 ' );
6317+ $ result = $ this ->assertQuery ( 'SELECT * FROM t ' );
6318+ $ this ->assertSame ( array ( '1 ' ), (array ) array_column ( $ result , 'id ' ) );
6319+
6320+ $ this ->assertQuery ( 'RELEASE SAVEPOINT sp1 ' );
6321+ $ this ->assertQuery ( 'ROLLBACK ' );
6322+ $ result = $ this ->assertQuery ( 'SELECT * FROM t ' );
6323+ $ this ->assertSame ( array (), (array ) array_column ( $ result , 'id ' ) );
6324+ }
6325+
6326+ public function testRollbackNonExistentTransactionSavepoint (): void {
6327+ $ this ->expectException ( 'WP_SQLite_Driver_Exception ' );
6328+ $ this ->expectExceptionMessage ( 'no such savepoint: sp1 ' );
6329+ $ this ->assertQuery ( 'ROLLBACK TO SAVEPOINT sp1 ' );
6330+ }
62976331}
0 commit comments