3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is database locks and the operation of the
13 # DEFERRED, IMMEDIATE, and EXCLUSIVE keywords as modifiers to the
16 # $Id: lock3.test,v 1.4 2009/03/28 15:04:24 drh Exp $
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
22 # Establish two connections to the same database. Put some
23 # sample data into the database.
26 file mkdir tempdir/t1/t2/t3
27 sqlite3 db2 ./tempdir/t1//t2/./t3//./../..//./../../tempdir/..//test.db//
30 INSERT INTO t1 VALUES(1);
37 # Get a deferred lock on the database using one connection. The
38 # other connection should still be able to write.
41 execsql {BEGIN DEFERRED TRANSACTION}
42 execsql {INSERT INTO t1 VALUES(2)} db2
43 execsql {END TRANSACTION}
44 execsql {SELECT * FROM t1}
47 # Get an immediate lock on the database using one connection. The
48 # other connection should be able to read the database but not write
52 execsql {BEGIN IMMEDIATE TRANSACTION}
53 catchsql {SELECT * FROM t1} db2
56 catchsql {INSERT INTO t1 VALUES(3)} db2
57 } {1 {database is locked}}
59 execsql {END TRANSACTION}
63 # Get an exclusive lock on the database using one connection. The
64 # other connection should be unable to read or write the database.
67 execsql {BEGIN EXCLUSIVE TRANSACTION}
68 catchsql {SELECT * FROM t1} db2
69 } {1 {database is locked}}
71 catchsql {INSERT INTO t1 VALUES(3)} db2
72 } {1 {database is locked}}
74 execsql {END TRANSACTION}