Small performance optimization in sqlite3VdbeRecordCompareWithSkip() for
[sqlite.git] / test / lock3.test
blobf771a193705a03f06d315565a38cc9b9ca25fd81
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.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.
25 do_test lock3-1.1 {
26   file mkdir tempdir/t1/t2/t3
27   sqlite3 db2 ./tempdir/t1//t2/./t3//./../..//./../../tempdir/..//test.db//
28   execsql {
29     CREATE TABLE t1(a);
30     INSERT INTO t1 VALUES(1);
31   }
32   execsql {
33     SELECT * FROM t1
34   } db2
35 } 1
37 # Get a deferred lock on the database using one connection.  The
38 # other connection should still be able to write.
40 do_test lock3-2.1 {
41   execsql {BEGIN DEFERRED TRANSACTION}
42   execsql {INSERT INTO t1 VALUES(2)} db2
43   execsql {END TRANSACTION}
44   execsql {SELECT * FROM t1}
45 } {1 2}
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
49 # it.
51 do_test lock3-3.1 {
52   execsql {BEGIN IMMEDIATE TRANSACTION}
53   catchsql {SELECT * FROM t1} db2
54 } {0 {1 2}}
55 do_test lock3-3.2 {
56   catchsql {INSERT INTO t1 VALUES(3)} db2
57 } {1 {database is locked}}
58 do_test lock3-3.3 {
59   execsql {END TRANSACTION}
60 } {}
63 # Get an exclusive lock on the database using one connection.  The
64 # other connection should be unable to read or write the database.
66 do_test lock3-4.1 {
67   execsql {BEGIN EXCLUSIVE TRANSACTION}
68   catchsql {SELECT * FROM t1} db2
69 } {1 {database is locked}}
70 do_test lock3-4.2 {
71   catchsql {INSERT INTO t1 VALUES(3)} db2
72 } {1 {database is locked}}
73 do_test lock3-4.3 {
74   execsql {END TRANSACTION}
75 } {}
77 catch {db2 close}
79 finish_test