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 #***********************************************************************
12 # $Id: sharedlock.test,v 1.1 2009/07/02 17:21:58 danielk1977 Exp $
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 set testprefix sharedlock
19 ifcapable !shared_cache {
24 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
28 do_test sharedlock-1.1 {
30 CREATE TABLE t1(a, b);
31 INSERT INTO t1 VALUES(1, 'one');
32 INSERT INTO t1 VALUES(2, 'two');
36 do_test sharedlock-1.2 {
38 db eval { SELECT * FROM t1 ORDER BY rowid } {
40 if {$a == 1} { catch { db eval "INSERT INTO t1 VALUES(3, 'three')" } }
42 # This should fail. Connection [db] has a read-lock on t1, which should
43 # prevent connection [db2] from obtaining the write-lock it needs to
44 # modify t1. At one point there was a bug causing the previous INSERT
45 # to drop the read-lock belonging to [db].
46 if {$a == 2} { catch { db2 eval "INSERT INTO t1 VALUES(4, 'four')" } }
49 } {1 one 2 two 3 three}
52 #-------------------------------------------------------------------------
53 # Test that a write-lock is taken on a table when its entire contents
54 # are deleted using the OP_Clear optimization.
56 foreach {tn delete_sql} {
57 1 { DELETE FROM t2 WHERE 1 }
61 DROP TABLE IF EXISTS t2;
62 CREATE TABLE t2(x, y);
63 INSERT INTO t2 VALUES(1, 2);
64 INSERT INTO t2 VALUES(3, 4);
67 do_test 2.2 { execsql { SELECT * FROM t2 } db2 } {1 2 3 4}
69 do_execsql_test 2.3 " BEGIN; $delete_sql; "
72 catchsql { SELECT * FROM t2 } db2
73 } {1 {database table is locked: t2}}
75 do_execsql_test 2.5 COMMIT
81 sqlite3_enable_shared_cache $::enable_shared_cache