@@ -6238,4 +6238,60 @@ public function testUserVariables(): void {
62386238 $ result = $ this ->assertQuery ( 'SELECT @my_var ' );
62396239 $ this ->assertEquals ( 3 , $ result [0 ]->{'@my_var ' } );
62406240 }
6241+
6242+ public function testLockingStatements (): void {
6243+ $ this ->assertQuery ( 'CREATE TABLE t (id INT) ' );
6244+
6245+ // When there is no lock, UNLOCK statement shouldn't fail.
6246+ $ this ->assertQuery ( 'UNLOCK TABLES ' );
6247+
6248+ // READ LOCK.
6249+ $ this ->assertQuery ( 'LOCK TABLES t READ ' );
6250+ $ this ->assertQuery ( 'UNLOCK TABLES ' );
6251+
6252+ // WRITE LOCK.
6253+ $ this ->assertQuery ( 'LOCK TABLES t WRITE ' );
6254+ $ this ->assertQuery ( 'UNLOCK TABLES ' );
6255+
6256+ // LOCK inside a transaction.
6257+ $ this ->assertQuery ( 'BEGIN ' );
6258+ $ this ->assertQuery ( 'LOCK TABLES t WRITE ' );
6259+ $ this ->assertQuery ( 'UNLOCK TABLES ' );
6260+ $ this ->assertQuery ( 'COMMIT ' );
6261+
6262+ // Transaction inside LOCK statements.
6263+ $ this ->assertQuery ( 'LOCK TABLES t WRITE ' );
6264+ $ this ->assertQuery ( 'BEGIN ' );
6265+ $ this ->assertQuery ( 'COMMIT ' );
6266+ $ this ->assertQuery ( 'UNLOCK TABLES ' );
6267+ }
6268+
6269+ public function testLockNonExistentTableForRead (): void {
6270+ $ this ->expectException ( 'WP_SQLite_Driver_Exception ' );
6271+ $ this ->expectExceptionMessage ( "Table 'wp.t' doesn't exist " );
6272+ $ this ->assertQuery ( 'LOCK TABLES t READ ' );
6273+ }
6274+
6275+ public function testLockNonExistentTableForWrite (): void {
6276+ $ this ->expectException ( 'WP_SQLite_Driver_Exception ' );
6277+ $ this ->expectExceptionMessage ( "Table 'wp.t' doesn't exist " );
6278+ $ this ->assertQuery ( 'LOCK TABLES t WRITE ' );
6279+ }
6280+
6281+ public function testLockMultipleWithNonExistentTable (): void {
6282+ $ this ->assertQuery ( 'CREATE TABLE t1 (id INT) ' );
6283+ $ this ->assertQuery ( 'CREATE TABLE t3 (id INT) ' );
6284+
6285+ $ this ->expectException ( 'WP_SQLite_Driver_Exception ' );
6286+ $ this ->expectExceptionMessage ( "Table 'wp.t2' doesn't exist " );
6287+ $ this ->assertQuery ( 'LOCK TABLES t1 READ, t2 READ, t3 WRITE ' );
6288+ }
6289+
6290+ public function testLockTemporaryTables (): void {
6291+ $ this ->assertQuery ( 'CREATE TEMPORARY TABLE t1 (id INT) ' );
6292+ $ this ->assertQuery ( 'CREATE TABLE t2 (id INT) ' );
6293+ $ this ->assertQuery ( 'CREATE TEMPORARY TABLE t3 (id INT) ' );
6294+ $ this ->assertQuery ( 'LOCK TABLES t1 READ, t2 READ, t3 WRITE ' );
6295+ $ this ->assertQuery ( 'UNLOCK TABLES ' );
6296+ }
62416297}
0 commit comments