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 # Test the btree mutex protocol for shared cache mode.
14 # $Id: shared4.test,v 1.2 2008/08/04 03:51:24 danielk1977 Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
21 # This script is only valid if we are running shared-cache mode in a
22 # threadsafe-capable database engine.
24 ifcapable !shared_cache||!compound {
28 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
30 # Prepare multiple databases in shared cache mode.
33 forcedelete test1.db test1.db-journal
34 forcedelete test2.db test2.db-journal
35 forcedelete test3.db test3.db-journal
36 forcedelete test4.db test4.db-journal
43 INSERT INTO t1 VALUES(111);
47 INSERT INTO t2 VALUES(222);
51 INSERT INTO t3 VALUES(333);
55 INSERT INTO t4 VALUES(444);
58 ATTACH DATABASE 'test2.db' AS two;
59 ATTACH DATABASE 'test3.db' AS three;
60 ATTACH DATABASE 'test4.db' AS four;
63 ATTACH DATABASE 'test4.db' AS four;
64 ATTACH DATABASE 'test3.db' AS three;
65 ATTACH DATABASE 'test1.db' AS one;
68 ATTACH DATABASE 'test1.db' AS one;
69 ATTACH DATABASE 'test2.db' AS two;
70 ATTACH DATABASE 'test4.db' AS four;
73 ATTACH DATABASE 'test3.db' AS three;
74 ATTACH DATABASE 'test2.db' AS two;
75 ATTACH DATABASE 'test1.db' AS one;
78 SELECT a FROM t1 UNION ALL
79 SELECT b FROM t2 UNION ALL
80 SELECT c FROM t3 UNION ALL
86 SELECT a FROM t1 UNION ALL
87 SELECT b FROM t2 UNION ALL
88 SELECT d FROM t4 UNION ALL
94 SELECT a FROM t1 UNION ALL
95 SELECT c FROM t3 UNION ALL
96 SELECT b FROM t2 UNION ALL
100 do_test shared4-1.4 {
102 SELECT a FROM t1 UNION ALL
103 SELECT c FROM t3 UNION ALL
104 SELECT d FROM t4 UNION ALL
108 do_test shared4-1.5 {
110 SELECT a FROM t1 UNION ALL
111 SELECT d FROM t4 UNION ALL
112 SELECT b FROM t2 UNION ALL
116 do_test shared4-1.6 {
118 SELECT a FROM t1 UNION ALL
119 SELECT d FROM t4 UNION ALL
120 SELECT c FROM t3 UNION ALL
124 do_test shared4-1.7 {
126 SELECT b FROM t2 UNION ALL
127 SELECT a FROM t1 UNION ALL
128 SELECT c FROM t3 UNION ALL
132 do_test shared4-1.8 {
134 SELECT b FROM t2 UNION ALL
135 SELECT a FROM t1 UNION ALL
136 SELECT d FROM t4 UNION ALL
140 do_test shared4-1.9 {
142 SELECT b FROM t2 UNION ALL
143 SELECT c FROM t3 UNION ALL
144 SELECT a FROM t1 UNION ALL
148 do_test shared4-1.10 {
150 SELECT b FROM t2 UNION ALL
151 SELECT c FROM t3 UNION ALL
152 SELECT d FROM t4 UNION ALL
156 do_test shared4-1.11 {
158 SELECT c FROM t3 UNION ALL
159 SELECT a FROM t1 UNION ALL
160 SELECT b FROM t2 UNION ALL
164 do_test shared4-1.12 {
166 SELECT c FROM t3 UNION ALL
167 SELECT a FROM t1 UNION ALL
168 SELECT d FROM t4 UNION ALL
173 do_test shared4-2.1 {
175 UPDATE t1 SET a=a+1000;
176 UPDATE t2 SET b=b+2000;
177 UPDATE t3 SET c=c+3000;
178 UPDATE t4 SET d=d+4000;
181 UPDATE t1 SET a=a+10000;
182 UPDATE t2 SET b=b+20000;
183 UPDATE t3 SET c=c+30000;
184 UPDATE t4 SET d=d+40000;
187 UPDATE t1 SET a=a+100000;
188 UPDATE t2 SET b=b+200000;
189 UPDATE t3 SET c=c+300000;
190 UPDATE t4 SET d=d+400000;
193 UPDATE t1 SET a=a+1000000;
194 UPDATE t2 SET b=b+2000000;
195 UPDATE t3 SET c=c+3000000;
196 UPDATE t4 SET d=d+4000000;
199 SELECT a FROM t1 UNION ALL
200 SELECT b FROM t2 UNION ALL
201 SELECT c FROM t3 UNION ALL
204 } {1111111 2222222 3333333 4444444}
205 do_test shared4-2.2 {
207 SELECT a FROM t1 UNION ALL
208 SELECT b FROM t2 UNION ALL
209 SELECT d FROM t4 UNION ALL
212 } {1111111 2222222 4444444 3333333}
213 do_test shared4-2.3 {
215 SELECT a FROM t1 UNION ALL
216 SELECT c FROM t3 UNION ALL
217 SELECT b FROM t2 UNION ALL
220 } {1111111 3333333 2222222 4444444}
221 do_test shared4-2.4 {
223 SELECT a FROM t1 UNION ALL
224 SELECT c FROM t3 UNION ALL
225 SELECT d FROM t4 UNION ALL
228 } {1111111 3333333 4444444 2222222}
236 sqlite3_enable_shared_cache $::enable_shared_cache