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
20 # This script is only valid if we are running shared-cache mode in a
21 # threadsafe-capable database engine.
23 ifcapable !shared_cache||!compound {
27 set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
29 # Prepare multiple databases in shared cache mode.
32 forcedelete test1.db test1.db-journal
33 forcedelete test2.db test2.db-journal
34 forcedelete test3.db test3.db-journal
35 forcedelete test4.db test4.db-journal
42 INSERT INTO t1 VALUES(111);
46 INSERT INTO t2 VALUES(222);
50 INSERT INTO t3 VALUES(333);
54 INSERT INTO t4 VALUES(444);
57 ATTACH DATABASE 'test2.db' AS two;
58 ATTACH DATABASE 'test3.db' AS three;
59 ATTACH DATABASE 'test4.db' AS four;
62 ATTACH DATABASE 'test4.db' AS four;
63 ATTACH DATABASE 'test3.db' AS three;
64 ATTACH DATABASE 'test1.db' AS one;
67 ATTACH DATABASE 'test1.db' AS one;
68 ATTACH DATABASE 'test2.db' AS two;
69 ATTACH DATABASE 'test4.db' AS four;
72 ATTACH DATABASE 'test3.db' AS three;
73 ATTACH DATABASE 'test2.db' AS two;
74 ATTACH DATABASE 'test1.db' AS one;
77 SELECT a FROM t1 UNION ALL
78 SELECT b FROM t2 UNION ALL
79 SELECT c FROM t3 UNION ALL
85 SELECT a FROM t1 UNION ALL
86 SELECT b FROM t2 UNION ALL
87 SELECT d FROM t4 UNION ALL
93 SELECT a FROM t1 UNION ALL
94 SELECT c FROM t3 UNION ALL
95 SELECT b FROM t2 UNION ALL
101 SELECT a FROM t1 UNION ALL
102 SELECT c FROM t3 UNION ALL
103 SELECT d FROM t4 UNION ALL
107 do_test shared4-1.5 {
109 SELECT a FROM t1 UNION ALL
110 SELECT d FROM t4 UNION ALL
111 SELECT b FROM t2 UNION ALL
115 do_test shared4-1.6 {
117 SELECT a FROM t1 UNION ALL
118 SELECT d FROM t4 UNION ALL
119 SELECT c FROM t3 UNION ALL
123 do_test shared4-1.7 {
125 SELECT b FROM t2 UNION ALL
126 SELECT a FROM t1 UNION ALL
127 SELECT c FROM t3 UNION ALL
131 do_test shared4-1.8 {
133 SELECT b FROM t2 UNION ALL
134 SELECT a FROM t1 UNION ALL
135 SELECT d FROM t4 UNION ALL
139 do_test shared4-1.9 {
141 SELECT b FROM t2 UNION ALL
142 SELECT c FROM t3 UNION ALL
143 SELECT a FROM t1 UNION ALL
147 do_test shared4-1.10 {
149 SELECT b FROM t2 UNION ALL
150 SELECT c FROM t3 UNION ALL
151 SELECT d FROM t4 UNION ALL
155 do_test shared4-1.11 {
157 SELECT c FROM t3 UNION ALL
158 SELECT a FROM t1 UNION ALL
159 SELECT b FROM t2 UNION ALL
163 do_test shared4-1.12 {
165 SELECT c FROM t3 UNION ALL
166 SELECT a FROM t1 UNION ALL
167 SELECT d FROM t4 UNION ALL
172 do_test shared4-2.1 {
174 UPDATE t1 SET a=a+1000;
175 UPDATE t2 SET b=b+2000;
176 UPDATE t3 SET c=c+3000;
177 UPDATE t4 SET d=d+4000;
180 UPDATE t1 SET a=a+10000;
181 UPDATE t2 SET b=b+20000;
182 UPDATE t3 SET c=c+30000;
183 UPDATE t4 SET d=d+40000;
186 UPDATE t1 SET a=a+100000;
187 UPDATE t2 SET b=b+200000;
188 UPDATE t3 SET c=c+300000;
189 UPDATE t4 SET d=d+400000;
192 UPDATE t1 SET a=a+1000000;
193 UPDATE t2 SET b=b+2000000;
194 UPDATE t3 SET c=c+3000000;
195 UPDATE t4 SET d=d+4000000;
198 SELECT a FROM t1 UNION ALL
199 SELECT b FROM t2 UNION ALL
200 SELECT c FROM t3 UNION ALL
203 } {1111111 2222222 3333333 4444444}
204 do_test shared4-2.2 {
206 SELECT a FROM t1 UNION ALL
207 SELECT b FROM t2 UNION ALL
208 SELECT d FROM t4 UNION ALL
211 } {1111111 2222222 4444444 3333333}
212 do_test shared4-2.3 {
214 SELECT a FROM t1 UNION ALL
215 SELECT c FROM t3 UNION ALL
216 SELECT b FROM t2 UNION ALL
219 } {1111111 3333333 2222222 4444444}
220 do_test shared4-2.4 {
222 SELECT a FROM t1 UNION ALL
223 SELECT c FROM t3 UNION ALL
224 SELECT d FROM t4 UNION ALL
227 } {1111111 3333333 4444444 2222222}
235 sqlite3_enable_shared_cache $::enable_shared_cache