1# 2009 July 2 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# 12# $Id: sharedlock.test,v 1.1 2009/07/02 17:21:58 danielk1977 Exp $ 13 14set testdir [file dirname $argv0] 15source $testdir/tester.tcl 16db close 17 18ifcapable !shared_cache { 19 finish_test 20 return 21} 22 23set ::enable_shared_cache [sqlite3_enable_shared_cache 1] 24sqlite3 db test.db 25sqlite3 db2 test.db 26 27do_test sharedlock-1.1 { 28 execsql { 29 CREATE TABLE t1(a, b); 30 INSERT INTO t1 VALUES(1, 'one'); 31 INSERT INTO t1 VALUES(2, 'two'); 32 } 33} {} 34 35do_test sharedlock-1.2 { 36 set res [list] 37 db eval { SELECT * FROM t1 ORDER BY rowid } { 38 lappend res $a $b 39 if {$a == 1} { catch { db eval "INSERT INTO t1 VALUES(3, 'three')" } } 40 41 # This should fail. Connection [db] has a read-lock on t1, which should 42 # prevent connection [db2] from obtaining the write-lock it needs to 43 # modify t1. At one point there was a bug causing the previous INSERT 44 # to drop the read-lock belonging to [db]. 45 if {$a == 2} { catch { db2 eval "INSERT INTO t1 VALUES(4, 'four')" } } 46 } 47 set res 48} {1 one 2 two 3 three} 49 50db close 51db2 close 52 53sqlite3_enable_shared_cache $::enable_shared_cache 54finish_test 55 56