aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/sqlite/unix/sqlite-3.5.1/test/lock3.test
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/sqlite/unix/sqlite-3.5.1/test/lock3.test')
-rw-r--r--libraries/sqlite/unix/sqlite-3.5.1/test/lock3.test78
1 files changed, 78 insertions, 0 deletions
diff --git a/libraries/sqlite/unix/sqlite-3.5.1/test/lock3.test b/libraries/sqlite/unix/sqlite-3.5.1/test/lock3.test
new file mode 100644
index 0000000..1835c66
--- /dev/null
+++ b/libraries/sqlite/unix/sqlite-3.5.1/test/lock3.test
@@ -0,0 +1,78 @@
1# 2001 September 15
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
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.
15#
16# $Id: lock3.test,v 1.1 2004/10/05 02:41:43 drh Exp $
17
18
19set testdir [file dirname $argv0]
20source $testdir/tester.tcl
21
22# Establish two connections to the same database. Put some
23# sample data into the database.
24#
25do_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
35
36# Get a deferred lock on the database using one connection. The
37# other connection should still be able to write.
38#
39do_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}
45
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.
49#
50do_test lock3-3.1 {
51 execsql {BEGIN IMMEDIATE TRANSACTION}
52 catchsql {SELECT * FROM t1} db2
53} {0 {1 2}}
54do_test lock3-3.2 {
55 catchsql {INSERT INTO t1 VALUES(3)} db2
56} {1 {database is locked}}
57do_test lock3-3.3 {
58 execsql {END TRANSACTION}
59} {}
60
61
62# Get an exclusive lock on the database using one connection. The
63# other connection should be unable to read or write the database.
64#
65do_test lock3-4.1 {
66 execsql {BEGIN EXCLUSIVE TRANSACTION}
67 catchsql {SELECT * FROM t1} db2
68} {1 {database is locked}}
69do_test lock3-4.2 {
70 catchsql {INSERT INTO t1 VALUES(3)} db2
71} {1 {database is locked}}
72do_test lock3-4.3 {
73 execsql {END TRANSACTION}
74} {}
75
76catch {db2 close}
77
78finish_test