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 # The tests in this file are intended to show if two connections attach
13 # to the same shared cache using different database names, views and
14 # virtual tables may still be accessed.
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
19 source $testdir/lock_common.tcl
20 set testprefix shared9
22 ifcapable !view||!trigger {
28 set enable_shared_cache [sqlite3_enable_shared_cache 1]
36 ATTACH 'test.db2' AS 'fred';
37 CREATE TABLE fred.t1(a, b, c);
38 CREATE VIEW fred.v1 AS SELECT * FROM t1;
40 CREATE TABLE fred.t2(a, b);
41 CREATE TABLE fred.t3(a, b);
42 CREATE TRIGGER fred.trig AFTER INSERT ON t2 BEGIN
44 INSERT INTO t3 SELECT * FROM t2;
46 INSERT INTO t2 VALUES(1, 2);
51 do_test 1.2 { db2 eval "ATTACH 'test.db2' AS 'jones'" } {}
52 do_test 1.3 { db2 eval "SELECT * FROM v1" } {}
53 do_test 1.4 { db2 eval "INSERT INTO t2 VALUES(3, 4)" } {}
58 CREATE VIRTUAL TABLE fred.t4 USING fts4;
59 INSERT INTO t4 VALUES('hello world');
65 INSERT INTO t4 VALUES('shared cache');
66 SELECT * FROM t4 WHERE t4 MATCH 'hello';
72 SELECT * FROM t4 WHERE t4 MATCH 'c*';
80 #-------------------------------------------------------------------------
81 # The following tests attempt to find a similar problem with collation
82 # sequence names - pointers to database handle specific allocations leaking
83 # into schema objects and being used after the original handle has been
86 forcedelete test.db test.db2
89 foreach x {collate1 collate2 collate3} {
90 proc $x {a b} { string compare $a $b }
96 CREATE TABLE t1(a, b, c COLLATE collate1);
97 CREATE INDEX i1 ON t1(a COLLATE collate2, c, b);
102 db2 eval "INSERT INTO t1 VALUES('abc', 'def', 'ghi')"
106 #-------------------------------------------------------------------------
107 # At one point, the following would cause a collation sequence belonging
108 # to connection [db1] to be invoked by a call to [db2 eval]. Which is a
109 # problem if [db1] has already been closed.
111 forcedelete test.db test.db2
115 proc mycollate_db1 {a b} {set ::invoked_mycollate_db1 1 ; string compare $a $b}
116 proc mycollate_db2 {a b} {string compare $a $b}
118 db1 collate mycollate mycollate_db1
119 db2 collate mycollate mycollate_db2
122 set ::invoked_mycollate_db1 0
124 CREATE TABLE t1(a COLLATE mycollate, CHECK (a IN ('one', 'two', 'three')));
125 INSERT INTO t1 VALUES('one');
128 set ::invoked_mycollate_db1
131 set ::invoked_mycollate_db1 0
133 INSERT INTO t1 VALUES('two');
136 set ::invoked_mycollate_db1
139 forcedelete test.db test.db2
142 db1 collate mycollate mycollate_db1
143 db2 collate mycollate mycollate_db2
146 set ::invoked_mycollate_db1 0
148 CREATE TABLE t1(a, CHECK (a COLLATE mycollate IN ('one', 'two', 'three')));
149 INSERT INTO t1 VALUES('one');
152 set ::invoked_mycollate_db1
155 set ::invoked_mycollate_db1 0
157 INSERT INTO t1 VALUES('two');
160 set ::invoked_mycollate_db1
163 #-------------------------------------------------------------------------
164 # This test verifies that a bug causing a busy-handler belonging to one
165 # shared-cache connection to be executed as a result of an sqlite3_step()
166 # on another has been fixed.
168 forcedelete test.db test.db2
172 proc busyhandler {handle args} {
173 set ::busyhandler_invoked_for $handle
176 db1 busy [list busyhandler db1]
177 db2 busy [list busyhandler db2]
182 CREATE TABLE t1(a, b);
183 CREATE TABLE t2(a, b);
184 INSERT INTO t1 VALUES(1, 2);
185 INSERT INTO t2 VALUES(1, 2);
187 # Keep this next COMMIT as a separate statement. This ensures that COMMIT
188 # has already been compiled and loaded into the tcl interface statement
189 # cache when it is attempted below.
193 INSERT INTO t1 VALUES(3, 4);
198 set ::tf [launch_testfixture]
209 db2 eval { SELECT * FROM t2 }
213 list [catch { db1 eval COMMIT } msg] $msg
214 } {1 {database is locked}}
216 # At one point the following would fail, showing that the busy-handler
217 # belonging to [db2] was invoked instead.
219 set ::busyhandler_invoked_for
229 sqlite3_enable_shared_cache $::enable_shared_cache