sl@0: # 2001 September 15 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The sl@0: # focus of this script is database locks and the operation of the sl@0: # DEFERRED, IMMEDIATE, and EXCLUSIVE keywords as modifiers to the sl@0: # BEGIN command. sl@0: # sl@0: # $Id: lock3.test,v 1.1 2004/10/05 02:41:43 drh Exp $ sl@0: sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # Establish two connections to the same database. Put some sl@0: # sample data into the database. sl@0: # sl@0: do_test lock3-1.1 { sl@0: sqlite3 db2 test.db sl@0: execsql { sl@0: CREATE TABLE t1(a); sl@0: INSERT INTO t1 VALUES(1); sl@0: } sl@0: execsql { sl@0: SELECT * FROM t1 sl@0: } db2 sl@0: } 1 sl@0: sl@0: # Get a deferred lock on the database using one connection. The sl@0: # other connection should still be able to write. sl@0: # sl@0: do_test lock3-2.1 { sl@0: execsql {BEGIN DEFERRED TRANSACTION} sl@0: execsql {INSERT INTO t1 VALUES(2)} db2 sl@0: execsql {END TRANSACTION} sl@0: execsql {SELECT * FROM t1} sl@0: } {1 2} sl@0: sl@0: # Get an immediate lock on the database using one connection. The sl@0: # other connection should be able to read the database but not write sl@0: # it. sl@0: # sl@0: do_test lock3-3.1 { sl@0: execsql {BEGIN IMMEDIATE TRANSACTION} sl@0: catchsql {SELECT * FROM t1} db2 sl@0: } {0 {1 2}} sl@0: do_test lock3-3.2 { sl@0: catchsql {INSERT INTO t1 VALUES(3)} db2 sl@0: } {1 {database is locked}} sl@0: do_test lock3-3.3 { sl@0: execsql {END TRANSACTION} sl@0: } {} sl@0: sl@0: sl@0: # Get an exclusive lock on the database using one connection. The sl@0: # other connection should be unable to read or write the database. sl@0: # sl@0: do_test lock3-4.1 { sl@0: execsql {BEGIN EXCLUSIVE TRANSACTION} sl@0: catchsql {SELECT * FROM t1} db2 sl@0: } {1 {database is locked}} sl@0: do_test lock3-4.2 { sl@0: catchsql {INSERT INTO t1 VALUES(3)} db2 sl@0: } {1 {database is locked}} sl@0: do_test lock3-4.3 { sl@0: execsql {END TRANSACTION} sl@0: } {} sl@0: sl@0: catch {db2 close} sl@0: sl@0: finish_test