author | sl@SLION-WIN7.fritz.box |
Fri, 15 Jun 2012 03:10:57 +0200 | |
changeset 0 | bde4ae8d615e |
permissions | -rw-r--r-- |
sl@0 | 1 |
# 2008 July 14 |
sl@0 | 2 |
# |
sl@0 | 3 |
# The author disclaims copyright to this source code. In place of |
sl@0 | 4 |
# a legal notice, here is a blessing: |
sl@0 | 5 |
# |
sl@0 | 6 |
# May you do good and not evil. |
sl@0 | 7 |
# May you find forgiveness for yourself and forgive others. |
sl@0 | 8 |
# May you share freely, never taking more than you give. |
sl@0 | 9 |
# |
sl@0 | 10 |
#*********************************************************************** |
sl@0 | 11 |
# |
sl@0 | 12 |
# Test the btree mutex protocol for shared cache mode. |
sl@0 | 13 |
# |
sl@0 | 14 |
# $Id: shared4.test,v 1.2 2008/08/04 03:51:24 danielk1977 Exp $ |
sl@0 | 15 |
|
sl@0 | 16 |
set testdir [file dirname $argv0] |
sl@0 | 17 |
source $testdir/tester.tcl |
sl@0 | 18 |
db close |
sl@0 | 19 |
puts hello |
sl@0 | 20 |
|
sl@0 | 21 |
# This script is only valid if we are running shared-cache mode in a |
sl@0 | 22 |
# threadsafe-capable database engine. |
sl@0 | 23 |
# |
sl@0 | 24 |
ifcapable !shared_cache||!compound { |
sl@0 | 25 |
finish_test |
sl@0 | 26 |
return |
sl@0 | 27 |
} |
sl@0 | 28 |
set ::enable_shared_cache [sqlite3_enable_shared_cache 1] |
sl@0 | 29 |
|
sl@0 | 30 |
# Prepare multiple databases in shared cache mode. |
sl@0 | 31 |
# |
sl@0 | 32 |
do_test shared4-1.1 { |
sl@0 | 33 |
file delete -force test1.db test1.db-journal |
sl@0 | 34 |
file delete -force test2.db test2.db-journal |
sl@0 | 35 |
file delete -force test3.db test3.db-journal |
sl@0 | 36 |
file delete -force test4.db test4.db-journal |
sl@0 | 37 |
sqlite3 db1 test1.db |
sl@0 | 38 |
sqlite3 db2 test2.db |
sl@0 | 39 |
sqlite3 db3 test3.db |
sl@0 | 40 |
sqlite3 db4 test4.db |
sl@0 | 41 |
db1 eval { |
sl@0 | 42 |
CREATE TABLE t1(a); |
sl@0 | 43 |
INSERT INTO t1 VALUES(111); |
sl@0 | 44 |
} |
sl@0 | 45 |
db2 eval { |
sl@0 | 46 |
CREATE TABLE t2(b); |
sl@0 | 47 |
INSERT INTO t2 VALUES(222); |
sl@0 | 48 |
} |
sl@0 | 49 |
db3 eval { |
sl@0 | 50 |
CREATE TABLE t3(c); |
sl@0 | 51 |
INSERT INTO t3 VALUES(333); |
sl@0 | 52 |
} |
sl@0 | 53 |
db4 eval { |
sl@0 | 54 |
CREATE TABLE t4(d); |
sl@0 | 55 |
INSERT INTO t4 VALUES(444); |
sl@0 | 56 |
} |
sl@0 | 57 |
db1 eval { |
sl@0 | 58 |
ATTACH DATABASE 'test2.db' AS two; |
sl@0 | 59 |
ATTACH DATABASE 'test3.db' AS three; |
sl@0 | 60 |
ATTACH DATABASE 'test4.db' AS four; |
sl@0 | 61 |
} |
sl@0 | 62 |
db2 eval { |
sl@0 | 63 |
ATTACH DATABASE 'test4.db' AS four; |
sl@0 | 64 |
ATTACH DATABASE 'test3.db' AS three; |
sl@0 | 65 |
ATTACH DATABASE 'test1.db' AS one; |
sl@0 | 66 |
} |
sl@0 | 67 |
db3 eval { |
sl@0 | 68 |
ATTACH DATABASE 'test1.db' AS one; |
sl@0 | 69 |
ATTACH DATABASE 'test2.db' AS two; |
sl@0 | 70 |
ATTACH DATABASE 'test4.db' AS four; |
sl@0 | 71 |
} |
sl@0 | 72 |
db4 eval { |
sl@0 | 73 |
ATTACH DATABASE 'test3.db' AS three; |
sl@0 | 74 |
ATTACH DATABASE 'test2.db' AS two; |
sl@0 | 75 |
ATTACH DATABASE 'test1.db' AS one; |
sl@0 | 76 |
} |
sl@0 | 77 |
db1 eval { |
sl@0 | 78 |
SELECT a FROM t1 UNION ALL |
sl@0 | 79 |
SELECT b FROM t2 UNION ALL |
sl@0 | 80 |
SELECT c FROM t3 UNION ALL |
sl@0 | 81 |
SELECT d FROM t4; |
sl@0 | 82 |
} |
sl@0 | 83 |
} {111 222 333 444} |
sl@0 | 84 |
do_test shared4-1.2 { |
sl@0 | 85 |
db2 eval { |
sl@0 | 86 |
SELECT a FROM t1 UNION ALL |
sl@0 | 87 |
SELECT b FROM t2 UNION ALL |
sl@0 | 88 |
SELECT d FROM t4 UNION ALL |
sl@0 | 89 |
SELECT c FROM t3; |
sl@0 | 90 |
} |
sl@0 | 91 |
} {111 222 444 333} |
sl@0 | 92 |
do_test shared4-1.3 { |
sl@0 | 93 |
db3 eval { |
sl@0 | 94 |
SELECT a FROM t1 UNION ALL |
sl@0 | 95 |
SELECT c FROM t3 UNION ALL |
sl@0 | 96 |
SELECT b FROM t2 UNION ALL |
sl@0 | 97 |
SELECT d FROM t4; |
sl@0 | 98 |
} |
sl@0 | 99 |
} {111 333 222 444} |
sl@0 | 100 |
do_test shared4-1.4 { |
sl@0 | 101 |
db4 eval { |
sl@0 | 102 |
SELECT a FROM t1 UNION ALL |
sl@0 | 103 |
SELECT c FROM t3 UNION ALL |
sl@0 | 104 |
SELECT d FROM t4 UNION ALL |
sl@0 | 105 |
SELECT b FROM t2; |
sl@0 | 106 |
} |
sl@0 | 107 |
} {111 333 444 222} |
sl@0 | 108 |
do_test shared4-1.5 { |
sl@0 | 109 |
db3 eval { |
sl@0 | 110 |
SELECT a FROM t1 UNION ALL |
sl@0 | 111 |
SELECT d FROM t4 UNION ALL |
sl@0 | 112 |
SELECT b FROM t2 UNION ALL |
sl@0 | 113 |
SELECT c FROM t3; |
sl@0 | 114 |
} |
sl@0 | 115 |
} {111 444 222 333} |
sl@0 | 116 |
do_test shared4-1.6 { |
sl@0 | 117 |
db4 eval { |
sl@0 | 118 |
SELECT a FROM t1 UNION ALL |
sl@0 | 119 |
SELECT d FROM t4 UNION ALL |
sl@0 | 120 |
SELECT c FROM t3 UNION ALL |
sl@0 | 121 |
SELECT b FROM t2; |
sl@0 | 122 |
} |
sl@0 | 123 |
} {111 444 333 222} |
sl@0 | 124 |
do_test shared4-1.7 { |
sl@0 | 125 |
db1 eval { |
sl@0 | 126 |
SELECT b FROM t2 UNION ALL |
sl@0 | 127 |
SELECT a FROM t1 UNION ALL |
sl@0 | 128 |
SELECT c FROM t3 UNION ALL |
sl@0 | 129 |
SELECT d FROM t4; |
sl@0 | 130 |
} |
sl@0 | 131 |
} {222 111 333 444} |
sl@0 | 132 |
do_test shared4-1.8 { |
sl@0 | 133 |
db2 eval { |
sl@0 | 134 |
SELECT b FROM t2 UNION ALL |
sl@0 | 135 |
SELECT a FROM t1 UNION ALL |
sl@0 | 136 |
SELECT d FROM t4 UNION ALL |
sl@0 | 137 |
SELECT c FROM t3; |
sl@0 | 138 |
} |
sl@0 | 139 |
} {222 111 444 333} |
sl@0 | 140 |
do_test shared4-1.9 { |
sl@0 | 141 |
db3 eval { |
sl@0 | 142 |
SELECT b FROM t2 UNION ALL |
sl@0 | 143 |
SELECT c FROM t3 UNION ALL |
sl@0 | 144 |
SELECT a FROM t1 UNION ALL |
sl@0 | 145 |
SELECT d FROM t4; |
sl@0 | 146 |
} |
sl@0 | 147 |
} {222 333 111 444} |
sl@0 | 148 |
do_test shared4-1.10 { |
sl@0 | 149 |
db4 eval { |
sl@0 | 150 |
SELECT b FROM t2 UNION ALL |
sl@0 | 151 |
SELECT c FROM t3 UNION ALL |
sl@0 | 152 |
SELECT d FROM t4 UNION ALL |
sl@0 | 153 |
SELECT a FROM t1; |
sl@0 | 154 |
} |
sl@0 | 155 |
} {222 333 444 111} |
sl@0 | 156 |
do_test shared4-1.11 { |
sl@0 | 157 |
db1 eval { |
sl@0 | 158 |
SELECT c FROM t3 UNION ALL |
sl@0 | 159 |
SELECT a FROM t1 UNION ALL |
sl@0 | 160 |
SELECT b FROM t2 UNION ALL |
sl@0 | 161 |
SELECT d FROM t4; |
sl@0 | 162 |
} |
sl@0 | 163 |
} {333 111 222 444} |
sl@0 | 164 |
do_test shared4-1.12 { |
sl@0 | 165 |
db2 eval { |
sl@0 | 166 |
SELECT c FROM t3 UNION ALL |
sl@0 | 167 |
SELECT a FROM t1 UNION ALL |
sl@0 | 168 |
SELECT d FROM t4 UNION ALL |
sl@0 | 169 |
SELECT b FROM t2; |
sl@0 | 170 |
} |
sl@0 | 171 |
} {333 111 444 222} |
sl@0 | 172 |
|
sl@0 | 173 |
do_test shared4-2.1 { |
sl@0 | 174 |
db1 eval { |
sl@0 | 175 |
UPDATE t1 SET a=a+1000; |
sl@0 | 176 |
UPDATE t2 SET b=b+2000; |
sl@0 | 177 |
UPDATE t3 SET c=c+3000; |
sl@0 | 178 |
UPDATE t4 SET d=d+4000; |
sl@0 | 179 |
} |
sl@0 | 180 |
db2 eval { |
sl@0 | 181 |
UPDATE t1 SET a=a+10000; |
sl@0 | 182 |
UPDATE t2 SET b=b+20000; |
sl@0 | 183 |
UPDATE t3 SET c=c+30000; |
sl@0 | 184 |
UPDATE t4 SET d=d+40000; |
sl@0 | 185 |
} |
sl@0 | 186 |
db3 eval { |
sl@0 | 187 |
UPDATE t1 SET a=a+100000; |
sl@0 | 188 |
UPDATE t2 SET b=b+200000; |
sl@0 | 189 |
UPDATE t3 SET c=c+300000; |
sl@0 | 190 |
UPDATE t4 SET d=d+400000; |
sl@0 | 191 |
} |
sl@0 | 192 |
db4 eval { |
sl@0 | 193 |
UPDATE t1 SET a=a+1000000; |
sl@0 | 194 |
UPDATE t2 SET b=b+2000000; |
sl@0 | 195 |
UPDATE t3 SET c=c+3000000; |
sl@0 | 196 |
UPDATE t4 SET d=d+4000000; |
sl@0 | 197 |
} |
sl@0 | 198 |
db1 eval { |
sl@0 | 199 |
SELECT a FROM t1 UNION ALL |
sl@0 | 200 |
SELECT b FROM t2 UNION ALL |
sl@0 | 201 |
SELECT c FROM t3 UNION ALL |
sl@0 | 202 |
SELECT d FROM t4; |
sl@0 | 203 |
} |
sl@0 | 204 |
} {1111111 2222222 3333333 4444444} |
sl@0 | 205 |
do_test shared4-2.2 { |
sl@0 | 206 |
db2 eval { |
sl@0 | 207 |
SELECT a FROM t1 UNION ALL |
sl@0 | 208 |
SELECT b FROM t2 UNION ALL |
sl@0 | 209 |
SELECT d FROM t4 UNION ALL |
sl@0 | 210 |
SELECT c FROM t3; |
sl@0 | 211 |
} |
sl@0 | 212 |
} {1111111 2222222 4444444 3333333} |
sl@0 | 213 |
do_test shared4-2.3 { |
sl@0 | 214 |
db3 eval { |
sl@0 | 215 |
SELECT a FROM t1 UNION ALL |
sl@0 | 216 |
SELECT c FROM t3 UNION ALL |
sl@0 | 217 |
SELECT b FROM t2 UNION ALL |
sl@0 | 218 |
SELECT d FROM t4; |
sl@0 | 219 |
} |
sl@0 | 220 |
} {1111111 3333333 2222222 4444444} |
sl@0 | 221 |
do_test shared4-2.4 { |
sl@0 | 222 |
db4 eval { |
sl@0 | 223 |
SELECT a FROM t1 UNION ALL |
sl@0 | 224 |
SELECT c FROM t3 UNION ALL |
sl@0 | 225 |
SELECT d FROM t4 UNION ALL |
sl@0 | 226 |
SELECT b FROM t2; |
sl@0 | 227 |
} |
sl@0 | 228 |
} {1111111 3333333 4444444 2222222} |
sl@0 | 229 |
|
sl@0 | 230 |
|
sl@0 | 231 |
db1 close |
sl@0 | 232 |
db2 close |
sl@0 | 233 |
db3 close |
sl@0 | 234 |
db4 close |
sl@0 | 235 |
|
sl@0 | 236 |
sqlite3_enable_shared_cache $::enable_shared_cache |
sl@0 | 237 |
finish_test |