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
|
# 2021 November 06
#
# 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.
#
#***********************************************************************
#
source [file join [file dirname [info script]] rbu_common.tcl]
set ::testprefix rbuexlock
db close
sqlite3_shutdown
sqlite3_config_uri 1
# Create a simple RBU database. That expects to write to a table:
#
# CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
#
proc create_rbu {filename} {
forcedelete $filename
sqlite3 rbu1 $filename
rbu1 eval {
CREATE TABLE data_t1(a, b, c, rbu_control);
INSERT INTO data_t1 VALUES(10, random(), random(), 0);
INSERT INTO data_t1 VALUES(20, random(), random(), 0);
INSERT INTO data_t1 VALUES(30, random(), random(), 0);
INSERT INTO data_t1 VALUES(40, random(), random(), 0);
INSERT INTO data_t1 VALUES(50, random(), random(), 0);
INSERT INTO data_t1 VALUES(60, random(), random(), 0);
INSERT INTO data_t1 VALUES(70, random(), random(), 0);
INSERT INTO data_t1 VALUES(80, random(), random(), 0);
}
rbu1 close
return $filename
}
reset_db
do_execsql_test 1.0 {
CREATE TABLE t1(a PRIMARY KEY, b INT, c INT);
CREATE INDEX t1b ON t1(b);
CREATE INDEX t1c ON t1(c);
INSERT INTO t1 VALUES(1, 2, 3);
}
create_rbu rbu1.db
do_test 1.1.0 {
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=1 rbu1.db
rbu step
} SQLITE_OK
do_catchsql_test 1.1.1 { SELECT * FROM t1 } {0 {1 2 3}}
do_test 1.2.0 {
for {set ii 0} {$ii < 10} {incr ii} {
rbu step
}
rbu step
} SQLITE_OK
do_catchsql_test 1.2.1 { SELECT * FROM t1 } {0 {1 2 3}}
do_test 1.2.2 {
db eval {PRAGMA journal_mode}
} {delete}
do_test 1.3.0 {
while {[file exists test.db-wal]==0} {
rbu step
}
} {}
do_catchsql_test 1.3.1 { SELECT * FROM t1 } {1 {database is locked}}
do_test 1.3.2 {
db eval {PRAGMA journal_mode}
} {delete}
do_test 1.4.0 {
rbu step
} SQLITE_OK
do_catchsql_test 1.4.1 { SELECT * FROM t1 } {1 {database is locked}}
do_test 1.4.2 {
db eval {PRAGMA journal_mode}
} {delete}
rbu close
do_test 1.5.0 {
file exists test.db-wal
} {1}
do_test 1.5.1 {
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=1 rbu1.db
file exists test.db-wal
} 1
do_catchsql_test 1.5.2 { SELECT * FROM t1 } {1 {database is locked}}
do_test 1.5.2 {
db eval {PRAGMA journal_mode}
} {delete}
do_test 1.6.0 {
rbu step
} SQLITE_OK
do_catchsql_test 1.6.1 { SELECT * FROM t1 } {1 {database is locked}}
do_test 1.6.2 {
db eval {PRAGMA journal_mode}
} {delete}
do_test 1.7.0 {
while {[rbu step]=="SQLITE_OK"} {}
rbu close
} SQLITE_DONE
do_catchsql_test 1.7.2 { SELECT count(*) FROM t1 } {0 9}
do_test 1.7.2 {
db eval {PRAGMA journal_mode}
} {delete}
reset_db
do_execsql_test 2.0 {
CREATE TABLE t1(a PRIMARY KEY, b INT, c INT);
CREATE INDEX t1b ON t1(b);
CREATE INDEX t1c ON t1(c);
INSERT INTO t1 VALUES(1, 2, 3);
}
create_rbu rbu1.db
do_test 2.1.0 {
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
rbu step
} SQLITE_OK
do_catchsql_test 2.1.1 { SELECT * FROM t1 } {0 {1 2 3}}
do_test 2.2.0 {
for {set ii 0} {$ii < 10} {incr ii} {
rbu step
}
rbu step
} SQLITE_OK
do_catchsql_test 2.2.1 { SELECT * FROM t1 } {0 {1 2 3}}
do_test 2.3.0 {
while {[file exists test.db-wal]==0} {
rbu step
}
} {}
do_test 2.3.1 {
llength [db eval {SELECT * FROM t1}]
} {27}
do_test 2.3.2 {
db eval {PRAGMA journal_mode}
} {wal}
do_test 2.4.0 {
rbu step
} SQLITE_OK
do_test 2.4.1 {
llength [db eval {SELECT * FROM t1}]
} {27}
do_test 2.4.2 {
db eval {PRAGMA journal_mode}
} {wal}
rbu close
do_test 2.5.0 {
db eval {PRAGMA journal_mode}
} {wal}
do_execsql_test 2.5.1 {
DELETE FROM t1;
} {}
create_rbu rbu1.db
do_test 3.1.0 {
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
rbu step
} SQLITE_ERROR
do_test 3.1.1 {
set rc [catch {rbu close} msg]
lappend rc $msg
} {1 {SQLITE_ERROR - cannot update wal mode database}}
db eval {PRAGMA journal_mode=DELETE}
create_rbu rbu1.db
do_test 3.2.0 {
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
rbu step
} SQLITE_OK
do_test 3.3.1 {
set rc [catch {rbu close} msg]
lappend rc $msg
} {0 SQLITE_OK}
db close
create_rbu rbu1.db
do_test 3.4.0 {
sqlite3rbu rbu file:test.db?rbu_exclusive_checkpoint=0 rbu1.db
rbu step
} SQLITE_OK
rbu close
finish_test
|