blob: 799e49dc810c3024b72b623707c65d6149151381 [file] [log] [blame]
dand3f8f942010-04-13 11:35:01 +00001# 2010 April 13
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# This file implements regression tests for SQLite library. The
12# focus of this file is testing the operation of the library in
13# "PRAGMA journal_mode=WAL" mode.
14#
dan7c246102010-04-12 19:00:29 +000015
16set testdir [file dirname $argv0]
17source $testdir/tester.tcl
dane264d982010-04-14 18:06:50 +000018source $testdir/lock_common.tcl
dan7c246102010-04-12 19:00:29 +000019
20proc reopen_db {} {
danb9bf16b2010-04-14 11:23:30 +000021 catch { db close }
dan7c246102010-04-12 19:00:29 +000022 file delete -force test.db test.db-wal
23 sqlite3_wal db test.db
dan7c246102010-04-12 19:00:29 +000024}
25
26proc sqlite3_wal {args} {
27 eval sqlite3 $args
28 [lindex $args 0] eval { PRAGMA journal_mode = wal }
29}
30
31#
32# These are 'warm-body' tests used while developing the WAL code. They
33# serve to prove that a few really simple cases work:
34#
35# wal-1.*: Read and write the database.
36# wal-2.*: Test MVCC with one reader, one writer.
37# wal-3.*: Test transaction rollback.
38# wal-4.*: Test savepoint/statement rollback.
39# wal-5.*: Test the temp database.
40# wal-6.*: Test creating databases with different page sizes.
41#
42
43do_test wal-0.1 {
44 execsql { PRAGMA journal_mode = wal }
45} {wal}
46
47do_test wal-1.0 {
48 execsql {
49 BEGIN;
50 CREATE TABLE t1(a, b);
51 }
52 list [file exists test.db-journal] [file exists test.db-wal]
53} {0 1}
54do_test wal-1.1 {
55 execsql COMMIT
56 list [file exists test.db-journal] [file exists test.db-wal]
57} {0 1}
58do_test wal-1.2 {
59 # There are now two pages in the log.
60 file size test.db-wal
61} [expr (20+1024)*2]
62
63do_test wal-1.3 {
64 execsql { SELECT * FROM sqlite_master }
65} {table t1 t1 2 {CREATE TABLE t1(a, b)}}
66
67do_test wal-1.4 {
68 execsql { INSERT INTO t1 VALUES(1, 2) }
69 execsql { INSERT INTO t1 VALUES(3, 4) }
70 execsql { INSERT INTO t1 VALUES(5, 6) }
71 execsql { INSERT INTO t1 VALUES(7, 8) }
72 execsql { INSERT INTO t1 VALUES(9, 10) }
73} {}
74
75do_test wal-1.5 {
76 execsql { SELECT * FROM t1 }
77} {1 2 3 4 5 6 7 8 9 10}
78
79do_test wal-2.1 {
80 sqlite3_wal db2 ./test.db
81 execsql { BEGIN; SELECT * FROM t1 } db2
82} {1 2 3 4 5 6 7 8 9 10}
83
84do_test wal-2.2 {
85 execsql { INSERT INTO t1 VALUES(11, 12) }
86 execsql { SELECT * FROM t1 }
87} {1 2 3 4 5 6 7 8 9 10 11 12}
88
89do_test wal-2.3 {
90 execsql { SELECT * FROM t1 } db2
91} {1 2 3 4 5 6 7 8 9 10}
92
93do_test wal-2.4 {
94 execsql { INSERT INTO t1 VALUES(13, 14) }
95 execsql { SELECT * FROM t1 }
96} {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
97
98do_test wal-2.5 {
99 execsql { SELECT * FROM t1 } db2
100} {1 2 3 4 5 6 7 8 9 10}
101
102do_test wal-2.6 {
103 execsql { COMMIT; SELECT * FROM t1 } db2
104} {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
105
106do_test wal-3.1 {
107 execsql { BEGIN; DELETE FROM t1 }
108 execsql { SELECT * FROM t1 }
109} {}
110do_test wal-3.2 {
111 execsql { SELECT * FROM t1 } db2
112} {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
113do_test wal-3.3 {
114 execsql { ROLLBACK }
115 execsql { SELECT * FROM t1 }
116} {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
117db2 close
118
119do_test wal-4.1 {
120 execsql {
121 DELETE FROM t1;
122 BEGIN;
123 INSERT INTO t1 VALUES('a', 'b');
124 SAVEPOINT sp;
125 INSERT INTO t1 VALUES('c', 'd');
126 SELECT * FROM t1;
127 }
128} {a b c d}
129do_test wal-4.2 {
130 execsql {
131 ROLLBACK TO sp;
132 SELECT * FROM t1;
133 }
134} {a b}
135do_test wal-4.3 {
136 execsql {
137 COMMIT;
138 SELECT * FROM t1;
139 }
140} {a b}
141
142do_test wal-5.1 {
143 execsql {
144 CREATE TEMP TABLE t2(a, b);
145 INSERT INTO t2 VALUES(1, 2);
146 }
147} {}
148do_test wal-5.2 {
149 execsql {
150 BEGIN;
151 INSERT INTO t2 VALUES(3, 4);
152 SELECT * FROM t2;
153 }
154} {1 2 3 4}
155do_test wal-5.3 {
156 execsql {
157 ROLLBACK;
158 SELECT * FROM t2;
159 }
160} {1 2}
161do_test wal-5.4 {
162 execsql {
163 CREATE TEMP TABLE t3(x UNIQUE);
164 BEGIN;
165 INSERT INTO t2 VALUES(3, 4);
166 INSERT INTO t3 VALUES('abc');
167 }
168 catchsql { INSERT INTO t3 VALUES('abc') }
169} {1 {column x is not unique}}
170do_test wal-5.5 {
171 execsql {
172 COMMIT;
173 SELECT * FROM t2;
174 }
175} {1 2 3 4}
176db close
177
178
179foreach sector {512 4096} {
180 sqlite3_simulate_device -sectorsize $sector
181 foreach pgsz {512 1024 2048 4096} {
182 file delete -force test.db test.db-wal
183 do_test wal-6.$sector.$pgsz.1 {
184 sqlite3_wal db test.db -vfs devsym
185 execsql "
186 PRAGMA page_size = $pgsz ;
187 "
188 execsql "
189 CREATE TABLE t1(a, b);
190 INSERT INTO t1 VALUES(1, 2);
191 "
192 db close
193 file size test.db
194 } [expr $pgsz*2]
195
196 do_test wal-6.$sector.$pgsz.2 {
197 file size test.db-wal
198 } {0}
199 }
200}
201
202do_test wal-7.1 {
203 file delete -force test.db test.db-wal
204 sqlite3_wal db test.db
205 execsql {
206 PRAGMA page_size = 1024;
207 CREATE TABLE t1(a, b);
208 INSERT INTO t1 VALUES(1, 2);
209 }
dan7c246102010-04-12 19:00:29 +0000210 list [file size test.db] [file size test.db-wal]
211} [list 0 [expr (1024+20)*3]]
212do_test wal-7.2 {
213 execsql { PRAGMA checkpoint }
214 list [file size test.db] [file size test.db-wal]
215} [list 2048 [expr (1024+20)*3]]
216
dan7c246102010-04-12 19:00:29 +0000217# Execute some transactions in auto-vacuum mode to test database file
218# truncation.
219#
danb9bf16b2010-04-14 11:23:30 +0000220do_test wal-8.1 {
dan7c246102010-04-12 19:00:29 +0000221 reopen_db
222 execsql {
223 PRAGMA auto_vacuum = 1;
224 PRAGMA auto_vacuum;
225 }
226} {1}
danb9bf16b2010-04-14 11:23:30 +0000227do_test wal-8.2 {
dan7c246102010-04-12 19:00:29 +0000228 execsql {
229 PRAGMA page_size = 1024;
230 CREATE TABLE t1(x);
231 INSERT INTO t1 VALUES(randomblob(900));
232 INSERT INTO t1 VALUES(randomblob(900));
233 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 4 */
234 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 8 */
235 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 16 */
236 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 32 */
237 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 64 */
238 PRAGMA checkpoint;
239 }
240 file size test.db
dan80a15262010-04-13 11:45:31 +0000241} [expr 68*1024]
danb9bf16b2010-04-14 11:23:30 +0000242do_test wal-8.3 {
dan7c246102010-04-12 19:00:29 +0000243 execsql {
244 DELETE FROM t1 WHERE rowid<54;
danf05c86d2010-04-13 11:56:03 +0000245 PRAGMA checkpoint;
dan7c246102010-04-12 19:00:29 +0000246 }
247 file size test.db
248} [expr 14*1024]
249
250# Run some "warm-body" tests to ensure that log-summary files with more
251# than 256 entries (log summaries that contain index blocks) work Ok.
252#
danb9bf16b2010-04-14 11:23:30 +0000253do_test wal-9.1 {
dan7c246102010-04-12 19:00:29 +0000254 reopen_db
255 execsql {
256 PRAGMA page_size = 1024;
257 CREATE TABLE t1(x PRIMARY KEY);
258 INSERT INTO t1 VALUES(randomblob(900));
259 INSERT INTO t1 VALUES(randomblob(900));
260 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 4 */
261 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 8 */
262 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 16 */
263 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 32 */
264 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 64 */
265 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 128 */
266 INSERT INTO t1 SELECT randomblob(900) FROM t1; /* 256 */
267 }
268 file size test.db
269} 0
danb9bf16b2010-04-14 11:23:30 +0000270do_test wal-9.2 {
dan7c246102010-04-12 19:00:29 +0000271 sqlite3_wal db2 test.db
272 execsql {PRAGMA integrity_check } db2
273} {ok}
274
danb9bf16b2010-04-14 11:23:30 +0000275do_test wal-9.3 {
dan7c246102010-04-12 19:00:29 +0000276 file delete -force test2.db test2.db-wal
277 file copy test.db test2.db
278 file copy test.db-wal test2.db-wal
279 sqlite3_wal db3 test2.db
280 execsql {PRAGMA integrity_check } db3
281} {ok}
282db3 close
283
danb9bf16b2010-04-14 11:23:30 +0000284do_test wal-9.4 {
dan7c246102010-04-12 19:00:29 +0000285 execsql { PRAGMA checkpoint }
286 db2 close
287 sqlite3_wal db2 test.db
288 execsql {PRAGMA integrity_check } db2
289} {ok}
290
dan80a15262010-04-13 11:45:31 +0000291foreach handle {db db2 db3} { catch { $handle close } }
292unset handle
293
danb9bf16b2010-04-14 11:23:30 +0000294#-------------------------------------------------------------------------
295# The following block of tests - wal-10.* - test that the WAL locking
dane264d982010-04-14 18:06:50 +0000296# scheme works in simple cases. This block of tests is run twice. Once
297# using multiple connections in the address space of the current process,
298# and once with all connections except one running in external processes.
danb9bf16b2010-04-14 11:23:30 +0000299#
dane264d982010-04-14 18:06:50 +0000300foreach code [list {
301 set ::code2_chan [launch_testfixture]
302 set ::code3_chan [launch_testfixture]
303 proc code2 {tcl} { testfixture $::code2_chan $tcl }
304 proc code3 {tcl} { testfixture $::code3_chan $tcl }
305 set tn 1
306} {
307 proc code2 {tcl} { uplevel #0 $tcl }
308 proc code3 {tcl} { uplevel #0 $tcl }
309 set tn 2
310}] {
danb9bf16b2010-04-14 11:23:30 +0000311
dane264d982010-04-14 18:06:50 +0000312 eval $code
313 reopen_db
314
315 # Open connections [db2] and [db3]. Depending on which iteration this
316 # is, the connections may be created in this interpreter, or in
317 # interpreters running in other OS processes. As such, the [db2] and [db3]
318 # commands should only be accessed within [code2] and [code3] blocks,
319 # respectively.
320 #
321 code2 { sqlite3 db2 test.db ; db2 eval { PRAGMA journal_mode = WAL } }
322 code3 { sqlite3 db3 test.db ; db3 eval { PRAGMA journal_mode = WAL } }
323
324 # Shorthand commands. Execute SQL using database connection [db2] or
325 # [db3]. Return the results.
326 #
327 proc sql2 {sql} { code2 [list db2 eval $sql] }
328 proc sql3 {sql} { code3 [list db3 eval $sql] }
329
330 # Initialize the database schema and contents.
331 #
332 do_test wal-10.$tn.1 {
333 execsql {
334 CREATE TABLE t1(a, b);
335 INSERT INTO t1 VALUES(1, 2);
danb9bf16b2010-04-14 11:23:30 +0000336 SELECT * FROM t1;
dane264d982010-04-14 18:06:50 +0000337 }
338 } {1 2}
danb9bf16b2010-04-14 11:23:30 +0000339
dane264d982010-04-14 18:06:50 +0000340 # Open a transaction and write to the database using [db]. Check that [db2]
341 # is still able to read the snapshot before the transaction was opened.
342 #
343 do_test wal-10.$tn.2 {
344 execsql { BEGIN; INSERT INTO t1 VALUES(3, 4); }
345 sql2 {SELECT * FROM t1}
346 } {1 2}
347
348 # Have [db] commit the transaction. Check that [db2] is now seeing the
349 # new, updated snapshot.
350 #
351 do_test wal-10.$tn.3 {
352 execsql { COMMIT }
353 sql2 {SELECT * FROM t1}
354 } {1 2 3 4}
355
356 # Have [db2] open a read transaction. Then write to the db via [db]. Check
357 # that [db2] is still seeing the original snapshot. Then read with [db3].
358 # [db3] should see the newly committed data.
359 #
360 do_test wal-10.$tn.4 {
361 sql2 { BEGIN ; SELECT * FROM t1}
362 } {1 2 3 4}
363 do_test wal-10.$tn.5 {
364 execsql { INSERT INTO t1 VALUES(5, 6); }
365 sql2 {SELECT * FROM t1}
366 } {1 2 3 4}
367 do_test wal-10.$tn.6 {
368 sql3 {SELECT * FROM t1}
369 } {1 2 3 4 5 6}
370 do_test wal-10.$tn.7 {
371 sql2 COMMIT
372 } {}
373
374 # Have [db2] open a write transaction. Then attempt to write to the
375 # database via [db]. This should fail (writer lock cannot be obtained).
376 #
377 # Then open a read-transaction with [db]. Commit the [db2] transaction
378 # to disk. Verify that [db] still cannot write to the database (because
379 # it is reading an old snapshot).
380 #
381 # Close the current [db] transaction. Open a new one. [db] can now write
382 # to the database (as it is not locked and [db] is reading the latest
383 # snapshot).
384 #
385 do_test wal-10.$tn.7 {
386 sql2 { BEGIN; INSERT INTO t1 VALUES(7, 8) ; }
387 catchsql { INSERT INTO t1 VALUES(9, 10) }
388 } {1 {database is locked}}
389 do_test wal-10.$tn.8 {
390 execsql { BEGIN ; SELECT * FROM t1 }
391 } {1 2 3 4 5 6}
392 do_test wal-10.$tn.9 {
393 sql2 COMMIT
394 catchsql { INSERT INTO t1 VALUES(9, 10) }
395 } {1 {database is locked}}
396 do_test wal-10.$tn.10 {
397 execsql { COMMIT; BEGIN; INSERT INTO t1 VALUES(9, 10); COMMIT; }
398 execsql { SELECT * FROM t1 }
399 } {1 2 3 4 5 6 7 8 9 10}
400
401 # Open a read transaction with [db2]. Check that this prevents [db] from
402 # checkpointing the database. But not from writing to it.
403 #
404 do_test wal-10.$tn.11 {
405 sql2 { BEGIN; SELECT * FROM t1 }
406 } {1 2 3 4 5 6 7 8 9 10}
407 do_test wal-10.$tn.12 {
408 catchsql { PRAGMA checkpoint }
409 } {1 {database is locked}}
410 do_test wal-10.$tn.13 {
411 execsql { INSERT INTO t1 VALUES(11, 12) }
412 sql2 {SELECT * FROM t1}
413 } {1 2 3 4 5 6 7 8 9 10}
414
415 # Connection [db2] is holding a lock on a snapshot, preventing [db] from
416 # checkpointing the database. Add a busy-handler to [db]. If [db2] completes
417 # its transaction from within the busy-handler, [db] is able to complete
418 # the checkpoint operation.
419 #
420 proc busyhandler x {
421 if {$x==4} { sql2 COMMIT }
422 if {$x<5} { return 0 }
423 return 1
danb9bf16b2010-04-14 11:23:30 +0000424 }
dane264d982010-04-14 18:06:50 +0000425 db busy busyhandler
426 do_test wal-10.$tn.14 {
427 execsql { PRAGMA checkpoint }
428 } {}
danb9bf16b2010-04-14 11:23:30 +0000429
dane264d982010-04-14 18:06:50 +0000430 # Similar to the test above. Except this time, a new read transaction is
431 # started (db3) while the checkpointer is waiting for an old one (db2) to
432 # finish. The checkpointer can finish, but any subsequent write operations
433 # must wait until after db3 has closed the read transaction, as db3 is a
434 # "region D" writer.
435 #
436 db busy {}
437 do_test wal-10.$tn.15 {
438 sql2 { BEGIN; SELECT * FROM t1; }
439 } {1 2 3 4 5 6 7 8 9 10 11 12}
440 do_test wal-10.$tn.16 {
441 catchsql { PRAGMA checkpoint }
442 } {1 {database is locked}}
443 proc busyhandler x {
444 if {$x==3} { sql3 { BEGIN; SELECT * FROM t1 } }
445 if {$x==4} { sql2 COMMIT }
446 if {$x<5} { return 0 }
447 return 1
448 }
449 db busy busyhandler
dan49320f82010-04-14 18:50:08 +0000450 do_test wal-10.$tn.17 {
dane264d982010-04-14 18:06:50 +0000451 execsql { PRAGMA checkpoint }
452 } {}
dan49320f82010-04-14 18:50:08 +0000453 do_test wal-10.$tn.18 {
dane264d982010-04-14 18:06:50 +0000454 sql3 { SELECT * FROM t1 }
455 } {1 2 3 4 5 6 7 8 9 10 11 12}
dan49320f82010-04-14 18:50:08 +0000456 do_test wal-10.$tn.19 {
dane264d982010-04-14 18:06:50 +0000457 catchsql { INSERT INTO t1 VALUES(13, 14) }
458 } {1 {database is locked}}
dan49320f82010-04-14 18:50:08 +0000459 do_test wal-10.$tn.20 {
dane264d982010-04-14 18:06:50 +0000460 execsql { SELECT * FROM t1 }
461 } {1 2 3 4 5 6 7 8 9 10 11 12}
dan49320f82010-04-14 18:50:08 +0000462 do_test wal-10.$tn.21 {
dane264d982010-04-14 18:06:50 +0000463 sql3 COMMIT
464 } {}
dan49320f82010-04-14 18:50:08 +0000465 do_test wal-10.$tn.22 {
dane264d982010-04-14 18:06:50 +0000466 execsql { INSERT INTO t1 VALUES(13, 14) }
467 execsql { SELECT * FROM t1 }
468 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
danb9bf16b2010-04-14 11:23:30 +0000469
dan49320f82010-04-14 18:50:08 +0000470 # Set [db3] up as a "region D" reader again. Then upgrade it to a writer
471 # and back down to a reader. Then, check that a checkpoint is not possible
472 # (as [db3] still has a snapshot locked).
473 #
474 do_test wal-10.$tn.23 {
475 execsql { PRAGMA checkpoint }
476 } {}
477 do_test wal-10.$tn.24 {
478 sql2 { BEGIN; SELECT * FROM t1; }
479 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14}
480 do_test wal-10.$tn.25 {
481 execsql { PRAGMA checkpoint }
482 } {}
483 do_test wal-10.$tn.26 {
484 catchsql { INSERT INTO t1 VALUES(15, 16) }
485 } {1 {database is locked}}
486 do_test wal-10.$tn.27 {
487 sql3 { INSERT INTO t1 VALUES(15, 16) }
488 } {}
489 do_test wal-10.$tn.28 {
490 code3 {
491 set ::STMT [sqlite3_prepare db3 "SELECT * FROM t1" -1 TAIL]
492 sqlite3_step $::STMT
493 }
494 sql3 COMMIT
495 execsql { SELECT * FROM t1 }
496 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
497 db busy {}
498 do_test wal-10.$tn.29 {
499 execsql { INSERT INTO t1 VALUES(17, 18) }
500 catchsql { PRAGMA checkpoint }
501 } {1 {database is locked}}
502 do_test wal-10.$tn.30 {
503 code3 { sqlite3_finalize $::STMT }
504 execsql { PRAGMA checkpoint }
505 } {}
506
507 # At one point, if a reader failed to upgrade to a writer because it
508 # was reading an old snapshot, the write-locks were not being released.
509 # Test that this bug has been fixed.
510 #
511 do_test wal-10.$tn.31 {
512 execsql { BEGIN ; SELECT * FROM t1 }
513 sql2 { INSERT INTO t1 VALUES(19, 20) }
514 catchsql { INSERT INTO t1 VALUES(21, 22) }
515 } {1 {database is locked}}
516 do_test wal-10.$tn.32 {
517 # This statement would fail when the bug was present.
518 sql2 { INSERT INTO t1 VALUES(21, 22) }
519 } {}
520 do_test wal-10.$tn.33 {
521 execsql { SELECT * FROM t1 ; COMMIT }
522 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18}
523 do_test wal-10.$tn.34 {
524 execsql { SELECT * FROM t1 }
525 } {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22}
526
dane264d982010-04-14 18:06:50 +0000527 catch { db close }
528 catch { code2 { db2 close } }
529 catch { code3 { db3 close } }
530 catch { close $::code2_chan }
531 catch { close $::code3_chan }
532}
533
dan4cc6fb62010-04-15 16:45:34 +0000534#-------------------------------------------------------------------------
535# This block of tests, wal-11.*, test that nothing goes terribly wrong
536# if frames must be written to the log file before a transaction is
537# committed (in order to free up memory).
538#
539do_test wal-11.1 {
540 reopen_db
541 execsql {
542 PRAGMA cache_size = 10;
543 PRAGMA page_size = 1024;
544 CREATE TABLE t1(x PRIMARY KEY);
545 }
546 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
547} {0 3}
548do_test wal-11.2 {
549 execsql { PRAGMA checkpoint }
550 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
551} {3 3}
552do_test wal-11.3 {
553 execsql { INSERT INTO t1 VALUES( randomblob(900) ) }
554 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
555} {3 4}
556
557do_test wal-11.4 {
558 execsql {
559 BEGIN;
560 INSERT INTO t1 SELECT randomblob(900) FROM t1; -- 2
561 INSERT INTO t1 SELECT randomblob(900) FROM t1; -- 4
562 INSERT INTO t1 SELECT randomblob(900) FROM t1; -- 8
563 INSERT INTO t1 SELECT randomblob(900) FROM t1; -- 16
564 }
565 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
566} {3 33}
567do_test wal-11.5 {
568 execsql {
569 SELECT count(*) FROM t1;
570 PRAGMA integrity_check;
571 }
572} {16 ok}
573do_test wal-11.6 {
574 execsql COMMIT
575 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
576} {3 42}
577do_test wal-11.7 {
578 execsql {
579 SELECT count(*) FROM t1;
580 PRAGMA integrity_check;
581 }
582} {16 ok}
583do_test wal-11.8 {
584 execsql { PRAGMA checkpoint }
585 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
586} {37 42}
587do_test wal-11.9 {
588 db close
589 sqlite3_wal db test.db
590 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
591} {37 0}
592
593do_test wal-11.10 {
594 execsql {
595 PRAGMA cache_size = 10;
596 BEGIN;
597 INSERT INTO t1 SELECT randomblob(900) FROM t1; -- 32
598 SELECT count(*) FROM t1;
599 }
600 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
601} {37 38}
602do_test wal-11.11 {
603 execsql {
604 SELECT count(*) FROM t1;
605 ROLLBACK;
606 SELECT count(*) FROM t1;
607 }
608} {32 16}
609do_test wal-11.12 {
610 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
611} {37 38}
612do_test wal-11.13 {
613 execsql {
614 INSERT INTO t1 VALUES( randomblob(900) );
615 SELECT count(*) FROM t1;
616 PRAGMA integrity_check;
617 }
618} {17 ok}
619do_test wal-11.14 {
620 list [expr [file size test.db]/1024] [expr [file size test.db-wal]/1044]
621} {37 38}
622
623
dan7c246102010-04-12 19:00:29 +0000624finish_test
625