summaryrefslogtreecommitdiffstats
path: root/test/shared4.test
blob: 88959db42d767600cc6b74965619f47a2222f587 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# 2008 July 14
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# Test the btree mutex protocol for shared cache mode.
#
# $Id: shared4.test,v 1.2 2008/08/04 03:51:24 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl
db close

# This script is only valid if we are running shared-cache mode in a
# threadsafe-capable database engine.
#
ifcapable !shared_cache||!compound {
  finish_test
  return
}
set ::enable_shared_cache [sqlite3_enable_shared_cache 1]

# Prepare multiple databases in shared cache mode.
#
do_test shared4-1.1 {
  forcedelete test1.db test1.db-journal
  forcedelete test2.db test2.db-journal
  forcedelete test3.db test3.db-journal
  forcedelete test4.db test4.db-journal
  sqlite3 db1 test1.db
  sqlite3 db2 test2.db
  sqlite3 db3 test3.db
  sqlite3 db4 test4.db
  db1 eval {
    CREATE TABLE t1(a);
    INSERT INTO t1 VALUES(111);
  }
  db2 eval {
    CREATE TABLE t2(b);
    INSERT INTO t2 VALUES(222);
  }
  db3 eval {
    CREATE TABLE t3(c);
    INSERT INTO t3 VALUES(333);
  }
  db4 eval {
    CREATE TABLE t4(d);
    INSERT INTO t4 VALUES(444);
  }
  db1 eval {
    ATTACH DATABASE 'test2.db' AS two;
    ATTACH DATABASE 'test3.db' AS three;
    ATTACH DATABASE 'test4.db' AS four;
  }
  db2 eval {
    ATTACH DATABASE 'test4.db' AS four;
    ATTACH DATABASE 'test3.db' AS three;
    ATTACH DATABASE 'test1.db' AS one;
  }
  db3 eval {
    ATTACH DATABASE 'test1.db' AS one;
    ATTACH DATABASE 'test2.db' AS two;
    ATTACH DATABASE 'test4.db' AS four;
  }
  db4 eval {
    ATTACH DATABASE 'test3.db' AS three;
    ATTACH DATABASE 'test2.db' AS two;
    ATTACH DATABASE 'test1.db' AS one;
  }
  db1 eval {
     SELECT a FROM t1 UNION ALL
     SELECT b FROM t2 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT d FROM t4;
  }
} {111 222 333 444}
do_test shared4-1.2 {
  db2 eval {
     SELECT a FROM t1 UNION ALL
     SELECT b FROM t2 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT c FROM t3;
  }
} {111 222 444 333}
do_test shared4-1.3 {
  db3 eval {
     SELECT a FROM t1 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT b FROM t2 UNION ALL
     SELECT d FROM t4;
  }
} {111 333 222 444}
do_test shared4-1.4 {
  db4 eval {
     SELECT a FROM t1 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT b FROM t2;
  }
} {111 333 444 222}
do_test shared4-1.5 {
  db3 eval {
     SELECT a FROM t1 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT b FROM t2 UNION ALL
     SELECT c FROM t3;
  }
} {111 444 222 333}
do_test shared4-1.6 {
  db4 eval {
     SELECT a FROM t1 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT b FROM t2;
  }
} {111 444 333 222}
do_test shared4-1.7 {
  db1 eval {
     SELECT b FROM t2 UNION ALL
     SELECT a FROM t1 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT d FROM t4;
  }
} {222 111 333 444}
do_test shared4-1.8 {
  db2 eval {
     SELECT b FROM t2 UNION ALL
     SELECT a FROM t1 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT c FROM t3;
  }
} {222 111 444 333}
do_test shared4-1.9 {
  db3 eval {
     SELECT b FROM t2 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT a FROM t1 UNION ALL
     SELECT d FROM t4;
  }
} {222 333 111 444}
do_test shared4-1.10 {
  db4 eval {
     SELECT b FROM t2 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT a FROM t1;
  }
} {222 333 444 111}
do_test shared4-1.11 {
  db1 eval {
     SELECT c FROM t3 UNION ALL
     SELECT a FROM t1 UNION ALL
     SELECT b FROM t2 UNION ALL
     SELECT d FROM t4;
  }
} {333 111 222 444}
do_test shared4-1.12 {
  db2 eval {
     SELECT c FROM t3 UNION ALL
     SELECT a FROM t1 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT b FROM t2;
  }
} {333 111 444 222}

do_test shared4-2.1 {
  db1 eval {
    UPDATE t1 SET a=a+1000;
    UPDATE t2 SET b=b+2000;
    UPDATE t3 SET c=c+3000;
    UPDATE t4 SET d=d+4000;
  }
  db2 eval {
    UPDATE t1 SET a=a+10000;
    UPDATE t2 SET b=b+20000;
    UPDATE t3 SET c=c+30000;
    UPDATE t4 SET d=d+40000;
  }
  db3 eval {
    UPDATE t1 SET a=a+100000;
    UPDATE t2 SET b=b+200000;
    UPDATE t3 SET c=c+300000;
    UPDATE t4 SET d=d+400000;
  }
  db4 eval {
    UPDATE t1 SET a=a+1000000;
    UPDATE t2 SET b=b+2000000;
    UPDATE t3 SET c=c+3000000;
    UPDATE t4 SET d=d+4000000;
  }
  db1 eval {
     SELECT a FROM t1 UNION ALL
     SELECT b FROM t2 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT d FROM t4;
  }
} {1111111 2222222 3333333 4444444}
do_test shared4-2.2 {
  db2 eval {
     SELECT a FROM t1 UNION ALL
     SELECT b FROM t2 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT c FROM t3;
  }
} {1111111 2222222 4444444 3333333}
do_test shared4-2.3 {
  db3 eval {
     SELECT a FROM t1 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT b FROM t2 UNION ALL
     SELECT d FROM t4;
  }
} {1111111 3333333 2222222 4444444}
do_test shared4-2.4 {
  db4 eval {
     SELECT a FROM t1 UNION ALL
     SELECT c FROM t3 UNION ALL
     SELECT d FROM t4 UNION ALL
     SELECT b FROM t2;
  }
} {1111111 3333333 4444444 2222222}


db1 close
db2 close
db3 close
db4 close

sqlite3_enable_shared_cache $::enable_shared_cache
finish_test