sl@0
|
1 |
# 2001 September 15
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library. The
|
sl@0
|
12 |
# focus of this script is database locks and the operation of the
|
sl@0
|
13 |
# DEFERRED, IMMEDIATE, and EXCLUSIVE keywords as modifiers to the
|
sl@0
|
14 |
# BEGIN command.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# $Id: lock3.test,v 1.1 2004/10/05 02:41:43 drh Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
set testdir [file dirname $argv0]
|
sl@0
|
20 |
source $testdir/tester.tcl
|
sl@0
|
21 |
|
sl@0
|
22 |
# Establish two connections to the same database. Put some
|
sl@0
|
23 |
# sample data into the database.
|
sl@0
|
24 |
#
|
sl@0
|
25 |
do_test lock3-1.1 {
|
sl@0
|
26 |
sqlite3 db2 test.db
|
sl@0
|
27 |
execsql {
|
sl@0
|
28 |
CREATE TABLE t1(a);
|
sl@0
|
29 |
INSERT INTO t1 VALUES(1);
|
sl@0
|
30 |
}
|
sl@0
|
31 |
execsql {
|
sl@0
|
32 |
SELECT * FROM t1
|
sl@0
|
33 |
} db2
|
sl@0
|
34 |
} 1
|
sl@0
|
35 |
|
sl@0
|
36 |
# Get a deferred lock on the database using one connection. The
|
sl@0
|
37 |
# other connection should still be able to write.
|
sl@0
|
38 |
#
|
sl@0
|
39 |
do_test lock3-2.1 {
|
sl@0
|
40 |
execsql {BEGIN DEFERRED TRANSACTION}
|
sl@0
|
41 |
execsql {INSERT INTO t1 VALUES(2)} db2
|
sl@0
|
42 |
execsql {END TRANSACTION}
|
sl@0
|
43 |
execsql {SELECT * FROM t1}
|
sl@0
|
44 |
} {1 2}
|
sl@0
|
45 |
|
sl@0
|
46 |
# Get an immediate lock on the database using one connection. The
|
sl@0
|
47 |
# other connection should be able to read the database but not write
|
sl@0
|
48 |
# it.
|
sl@0
|
49 |
#
|
sl@0
|
50 |
do_test lock3-3.1 {
|
sl@0
|
51 |
execsql {BEGIN IMMEDIATE TRANSACTION}
|
sl@0
|
52 |
catchsql {SELECT * FROM t1} db2
|
sl@0
|
53 |
} {0 {1 2}}
|
sl@0
|
54 |
do_test lock3-3.2 {
|
sl@0
|
55 |
catchsql {INSERT INTO t1 VALUES(3)} db2
|
sl@0
|
56 |
} {1 {database is locked}}
|
sl@0
|
57 |
do_test lock3-3.3 {
|
sl@0
|
58 |
execsql {END TRANSACTION}
|
sl@0
|
59 |
} {}
|
sl@0
|
60 |
|
sl@0
|
61 |
|
sl@0
|
62 |
# Get an exclusive lock on the database using one connection. The
|
sl@0
|
63 |
# other connection should be unable to read or write the database.
|
sl@0
|
64 |
#
|
sl@0
|
65 |
do_test lock3-4.1 {
|
sl@0
|
66 |
execsql {BEGIN EXCLUSIVE TRANSACTION}
|
sl@0
|
67 |
catchsql {SELECT * FROM t1} db2
|
sl@0
|
68 |
} {1 {database is locked}}
|
sl@0
|
69 |
do_test lock3-4.2 {
|
sl@0
|
70 |
catchsql {INSERT INTO t1 VALUES(3)} db2
|
sl@0
|
71 |
} {1 {database is locked}}
|
sl@0
|
72 |
do_test lock3-4.3 {
|
sl@0
|
73 |
execsql {END TRANSACTION}
|
sl@0
|
74 |
} {}
|
sl@0
|
75 |
|
sl@0
|
76 |
catch {db2 close}
|
sl@0
|
77 |
|
sl@0
|
78 |
finish_test
|