CDXLPlay added with permission from Fredik Wikstrom.
[AROS-Contrib.git] / sqlite3 / test / lock3.test
blob1835c66f79c04feb06cf2adf00ebac2792b875b1
1 # 2001 September 15
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
14 # BEGIN command.
16 # $Id: lock3.test,v 1.1 2004/10/05 02:41:43 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.
25 do_test lock3-1.1 {
26   sqlite3 db2 test.db
27   execsql {
28     CREATE TABLE t1(a);
29     INSERT INTO t1 VALUES(1);
30   }
31   execsql {
32     SELECT * FROM t1
33   } db2
34 } 1
36 # Get a deferred lock on the database using one connection.  The
37 # other connection should still be able to write.
39 do_test lock3-2.1 {
40   execsql {BEGIN DEFERRED TRANSACTION}
41   execsql {INSERT INTO t1 VALUES(2)} db2
42   execsql {END TRANSACTION}
43   execsql {SELECT * FROM t1}
44 } {1 2}
46 # Get an immediate lock on the database using one connection.  The
47 # other connection should be able to read the database but not write
48 # it.
50 do_test lock3-3.1 {
51   execsql {BEGIN IMMEDIATE TRANSACTION}
52   catchsql {SELECT * FROM t1} db2
53 } {0 {1 2}}
54 do_test lock3-3.2 {
55   catchsql {INSERT INTO t1 VALUES(3)} db2
56 } {1 {database is locked}}
57 do_test lock3-3.3 {
58   execsql {END TRANSACTION}
59 } {}
62 # Get an exclusive lock on the database using one connection.  The
63 # other connection should be unable to read or write the database.
65 do_test lock3-4.1 {
66   execsql {BEGIN EXCLUSIVE TRANSACTION}
67   catchsql {SELECT * FROM t1} db2
68 } {1 {database is locked}}
69 do_test lock3-4.2 {
70   catchsql {INSERT INTO t1 VALUES(3)} db2
71 } {1 {database is locked}}
72 do_test lock3-4.3 {
73   execsql {END TRANSACTION}
74 } {}
76 catch {db2 close}
78 finish_test