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 #***********************************************************************
11 # This file implements regression tests for SQLite library. The focus
12 # of these tests is the journal mode pragma.
14 # $Id: jrnlmode.test,v 1.16 2009/06/05 17:09:12 drh Exp $
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
19 ifcapable {!pager_pragmas} {
24 if {[info exists TEMP_STORE] && $TEMP_STORE>=2} {
25 set temp_persist memory
26 set temp_delete memory
27 set temp_truncate memory
30 set temp_persist persist
31 set temp_delete delete
32 set temp_truncate truncate
36 proc temp_journal_mode {newmode} {
37 if {[info exists ::TEMP_STORE] && $::TEMP_STORE>=2} {
38 if {$newmode ne "off" && $newmode ne "memory"} {
39 execsql {PRAGMA temp.journal_mode}
40 set newmode [db one {PRAGMA temp.journal_mode}]
46 #----------------------------------------------------------------------
47 # Test cases jrnlmode-1.X test the PRAGMA logic.
49 do_test jrnlmode-1.0 {
52 PRAGMA main.journal_mode;
53 PRAGMA temp.journal_mode;
55 } [list delete delete [temp_journal_mode delete]]
56 do_test jrnlmode-1.1 {
58 PRAGMA journal_mode = persist;
61 do_test jrnlmode-1.2 {
64 PRAGMA main.journal_mode;
65 PRAGMA temp.journal_mode;
67 } [list persist persist [temp_journal_mode persist]]
68 do_test jrnlmode-1.4 {
70 PRAGMA journal_mode = off;
73 do_test jrnlmode-1.5 {
76 PRAGMA main.journal_mode;
77 PRAGMA temp.journal_mode;
79 } [list off off [temp_journal_mode off]]
80 do_test jrnlmode-1.6 {
82 PRAGMA journal_mode = delete;
85 do_test jrnlmode-1.7 {
88 PRAGMA main.journal_mode;
89 PRAGMA Temp.journal_mode;
91 } [list delete delete [temp_journal_mode delete]]
92 do_test jrnlmode-1.7.1 {
94 PRAGMA journal_mode = truncate;
97 do_test jrnlmode-1.7.2 {
100 PRAGMA main.journal_mode;
101 PRAGMA temp.journal_mode;
103 } [list truncate truncate [temp_journal_mode truncate]]
104 do_test jrnlmode-1.8 {
106 PRAGMA journal_mode = off;
107 PRAGMA journal_mode = invalid;
111 do_test jrnlmode-1.9 {
113 PRAGMA journal_mode = PERSIST;
114 ATTACH ':memory:' as aux1;
117 PRAGMA main.journal_mode;
118 PRAGMA aux1.journal_mode;
121 do_test jrnlmode-1.10 {
123 PRAGMA main.journal_mode = OFF;
126 PRAGMA main.journal_mode;
127 PRAGMA temp.journal_mode;
128 PRAGMA aux1.journal_mode;
130 } [list off [temp_journal_mode persist] memory]
131 do_test jrnlmode-1.11 {
136 do_test jrnlmode-1.12 {
138 ATTACH ':memory:' as aux2;
141 PRAGMA main.journal_mode;
142 PRAGMA aux1.journal_mode;
143 PRAGMA aux2.journal_mode;
145 } {off memory memory}
146 do_test jrnlmode-1.13 {
147 # The journal-mode used by in-memory databases cannot be changed.
149 PRAGMA aux1.journal_mode = DELETE;
152 PRAGMA main.journal_mode;
153 PRAGMA aux1.journal_mode;
154 PRAGMA aux2.journal_mode;
156 } {off memory memory}
157 do_test jrnlmode-1.14 {
159 PRAGMA journal_mode = delete;
162 PRAGMA main.journal_mode;
163 PRAGMA temp.journal_mode;
164 PRAGMA aux1.journal_mode;
165 PRAGMA aux2.journal_mode;
167 } [list delete [temp_journal_mode delete] memory memory]
168 do_test jrnlmode-1.15 {
170 ATTACH ':memory:' as aux3;
173 PRAGMA main.journal_mode;
174 PRAGMA temp.journal_mode;
175 PRAGMA aux1.journal_mode;
176 PRAGMA aux2.journal_mode;
177 PRAGMA aux3.journal_mode;
179 } [list delete [temp_journal_mode delete] memory memory memory]
180 do_test jrnlmode-1.16 {
182 PRAGMA journal_mode = TRUNCATE;
185 PRAGMA main.journal_mode;
186 PRAGMA temp.journal_mode;
187 PRAGMA aux1.journal_mode;
188 PRAGMA aux2.journal_mode;
189 PRAGMA aux3.journal_mode;
191 } [list truncate [temp_journal_mode truncate] memory memory memory]
193 do_test jrnlmode-1.99 {
204 do_test jrnlmode-2.1 {
206 ATTACH 'test2.db' AS aux;
207 PRAGMA main.journal_mode = persist;
208 PRAGMA aux.journal_mode = persist;
209 CREATE TABLE abc(a, b, c);
210 CREATE TABLE aux.def(d, e, f);
214 INSERT INTO abc VALUES(1, 2, 3);
215 INSERT INTO def VALUES(4, 5, 6);
218 list [file exists test.db-journal] [file exists test2.db-journal]
221 do_test jrnlmode-2.2 {
222 file size test.db-journal
225 do_test jrnlmode-2.3 {
231 do_test jrnlmode-2.4 {
232 file size test.db-journal
235 do_test jrnlmode-2.5 {
241 #----------------------------------------------------------------------
242 # Test caes jrnlmode-3.X verify that ticket #3127 has been fixed.
249 do_test jrnlmode-3.1 {
251 CREATE TABLE x(n INTEGER);
252 ATTACH 'test2.db' AS a;
253 create table a.x ( n integer );
254 insert into a.x values(1);
255 insert into a.x values (2);
256 insert into a.x values (3);
257 insert into a.x values (4);
261 do_test jrnlmode-3.2 {
262 execsql { PRAGMA journal_mode=off; }
265 INSERT OR IGNORE INTO main.x SELECT * FROM a.x;
271 ifcapable autovacuum&&pragma {
275 do_test jrnlmode-4.1 {
277 PRAGMA cache_size = 1;
278 PRAGMA auto_vacuum = 1;
279 CREATE TABLE abc(a, b, c);
281 execsql { PRAGMA page_count }
284 do_test jrnlmode-4.2 {
285 execsql { PRAGMA journal_mode = off }
288 do_test jrnlmode-4.3 {
289 execsql { INSERT INTO abc VALUES(1, 2, randomblob(2000)) }
292 # This will attempt to truncate the database file. Check that this
293 # is not a problem when journal_mode=off.
294 do_test jrnlmode-4.4 {
295 execsql { DELETE FROM abc }
298 integrity_check jrnlmode-4.5
301 #------------------------------------------------------------------------
302 # The following test caes, jrnlmode-5.*, test the journal_size_limit
305 if {[atomic_batch_write test.db]==0} {
307 forcedelete test.db test2.db test3.db
310 do_test jrnlmode-5.1 {
311 execsql {pragma page_size=1024}
312 execsql {pragma journal_mode=persist}
315 do_test jrnlmode-5.2 {
316 execsql { PRAGMA journal_size_limit }
318 do_test jrnlmode-5.3 {
320 ATTACH 'test2.db' AS aux;
321 PRAGMA aux.journal_mode=persist;
322 PRAGMA aux.journal_size_limit;
325 do_test jrnlmode-5.4.1 {
326 execsql { PRAGMA aux.journal_size_limit = 999999999999 }
328 do_test jrnlmode-5.4.2 {
329 execsql { PRAGMA aux.journal_size_limit = 10240 }
331 do_test jrnlmode-5.5 {
332 execsql { PRAGMA main.journal_size_limit = 20480 }
334 do_test jrnlmode-5.6 {
335 execsql { PRAGMA journal_size_limit }
337 do_test jrnlmode-5.7 {
338 execsql { PRAGMA aux.journal_size_limit }
341 do_test jrnlmode-5.8 {
343 ATTACH 'test3.db' AS aux2;
344 PRAGMA aux2.journal_mode=persist;
348 do_test jrnlmode-5.9 {
350 CREATE TABLE main.t1(a, b, c);
351 CREATE TABLE aux.t2(a, b, c);
352 CREATE TABLE aux2.t3(a, b, c);
355 do_test jrnlmode-5.10 {
357 [file exists test.db-journal] \
358 [file exists test2.db-journal] \
359 [file exists test3.db-journal]
361 do_test jrnlmode-5.11 {
364 INSERT INTO t3 VALUES(randomblob(1000),randomblob(1000),randomblob(1000));
366 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
368 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
370 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
372 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
374 SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3;
375 INSERT INTO t2 SELECT * FROM t3;
376 INSERT INTO t1 SELECT * FROM t2;
380 [file exists test.db-journal] \
381 [file exists test2.db-journal] \
382 [file exists test3.db-journal] \
383 [file size test.db-journal] \
384 [file size test2.db-journal] \
385 [file size test3.db-journal]
388 do_test jrnlmode-5.12 {
391 UPDATE t1 SET a = randomblob(1000);
393 expr {[file size test.db-journal]>30000}
395 do_test jrnlmode-5.13 {
397 file size test.db-journal
400 do_test jrnlmode-5.14 {
403 UPDATE t2 SET a = randomblob(1000);
405 expr {[file size test2.db-journal]>30000}
407 do_test jrnlmode-5.15 {
409 file size test2.db-journal
412 do_test jrnlmode-5.16 {
415 UPDATE t3 SET a = randomblob(1000);
417 set journalsize [file size test3.db-journal]
418 expr {$journalsize>30000}
420 do_test jrnlmode-5.17 {
422 set sz [file size test3.db-journal]
423 expr {$sz>=$journalsize}
426 do_test jrnlmode-5.18 {
428 PRAGMA journal_size_limit = -4;
430 UPDATE t1 SET a = randomblob(1000);
432 set journalsize [file size test.db-journal]
433 expr {$journalsize>30000}
435 do_test jrnlmode-5.19 {
437 set sz [file size test.db-journal]
438 expr {$sz>=$journalsize}
441 # Test a size-limit of 0.
443 do_test jrnlmode-5.20 {
445 PRAGMA journal_size_limit = 0;
447 UPDATE t1 SET a = randomblob(1000);
450 do_test jrnlmode-5.21 {
451 expr {[file size test.db-journal] > 1024}
453 do_test jrnlmode-5.22 {
455 list [file exists test.db-journal] [file size test.db-journal]
461 if {[atomic_batch_write test.db]==0} {
462 # These tests are not run as part of the "journaltest" permutation,
463 # as the test_journal.c layer is incompatible with in-memory journaling.
464 if {[permutation] ne "journaltest"} {
466 do_test jrnlmode-6.1 {
468 PRAGMA journal_mode = truncate;
469 CREATE TABLE t4(a, b);
471 INSERT INTO t4 VALUES(1, 2);
472 PRAGMA journal_mode = memory;
474 } {truncate truncate}
475 do_test jrnlmode-6.2 {
476 file exists test.db-journal
478 do_test jrnlmode-6.3 {
484 do_test jrnlmode-6.4 {
485 file exists test.db-journal
487 do_test jrnlmode-6.5 {
489 PRAGMA journal_mode = MEMORY;
491 INSERT INTO t4 VALUES(3, 4);
493 file exists test.db-journal
495 do_test jrnlmode-6.7 {
501 do_test jrnlmode-6.8 {
502 file exists test.db-journal
504 do_test jrnlmode-6.9 {
506 PRAGMA journal_mode = DELETE;
507 BEGIN IMMEDIATE; INSERT INTO t4 VALUES(1,2); COMMIT;
509 file exists test.db-journal
517 do_test jrnlmode-7.1 {
518 foreach f [glob -nocomplain test.db*] { forcedelete $f }
521 PRAGMA journal_mode = memory;
522 PRAGMA auto_vacuum = 0;
523 PRAGMA page_size = 1024;
524 PRAGMA user_version = 5;
528 do_test jrnlmode-7.2 { file size test.db } {1024}
531 do_execsql_test jrnlmode-8.1 { PRAGMA locking_mode=EXCLUSIVE } {exclusive}
532 do_execsql_test jrnlmode-8.2 { CREATE TABLE t1(x) } {}
533 do_execsql_test jrnlmode-8.3 { INSERT INTO t1 VALUES(123) } {}
534 do_execsql_test jrnlmode-8.4 { SELECT * FROM t1 } {123}
535 do_execsql_test jrnlmode-8.5 { PRAGMA journal_mode=PERSIST } {persist}
536 do_execsql_test jrnlmode-8.6 { PRAGMA journal_mode=DELETE } {delete}
537 do_execsql_test jrnlmode-8.7 { PRAGMA journal_mode=TRUNCATE } {truncate}
538 do_execsql_test jrnlmode-8.8 { PRAGMA journal_mode=DELETE } {delete}
539 do_execsql_test jrnlmode-8.9 { CREATE TABLE t2(y) } {}
540 do_execsql_test jrnlmode-8.10 { INSERT INTO t2 VALUES(456) } {}
541 do_execsql_test jrnlmode-8.11 { SELECT * FROM t1, t2 } {123 456}
542 do_execsql_test jrnlmode-8.12 { PRAGMA locking_mode=NORMAL } {normal}
543 do_execsql_test jrnlmode-8.13 { PRAGMA journal_mode=PERSIST } {persist}
544 do_execsql_test jrnlmode-8.14 { PRAGMA journal_mode=TRUNCATE } {truncate}
545 do_execsql_test jrnlmode-8.15 { PRAGMA journal_mode=PERSIST } {persist}
546 do_execsql_test jrnlmode-8.16 { PRAGMA journal_mode=DELETE } {delete}
547 do_execsql_test jrnlmode-8.17 { PRAGMA journal_mode=TRUNCATE } {truncate}
548 do_execsql_test jrnlmode-8.18 { PRAGMA locking_mode=EXCLUSIVE } {exclusive}
549 do_execsql_test jrnlmode-8.19 { CREATE TABLE t3(z) } {}
550 do_execsql_test jrnlmode-8.20 { BEGIN IMMEDIATE } {}
551 do_execsql_test jrnlmode-8.21 { PRAGMA journal_mode=DELETE } {delete}
552 do_execsql_test jrnlmode-8.22 { COMMIT } {}
553 do_execsql_test jrnlmode-8.23 { PRAGMA journal_mode=DELETE } {delete}
554 do_execsql_test jrnlmode-8.24 { PRAGMA journal_mode=TRUNCATE } {truncate}
555 do_execsql_test jrnlmode-8.25 { PRAGMA locking_mode=NORMAL } {normal}
556 do_execsql_test jrnlmode-8.26 { CREATE TABLE t4(w) } {}
557 do_execsql_test jrnlmode-8.27 { BEGIN IMMEDIATE } {}
558 do_execsql_test jrnlmode-8.28 { PRAGMA journal_mode=DELETE } {delete}
559 do_execsql_test jrnlmode-8.29 { COMMIT } {}
560 do_execsql_test jrnlmode-8.30 { PRAGMA journal_mode=DELETE } {delete}
562 # Assertion fault on 2015-05-01
563 do_test jrnlmode-9.1 {
566 db2 eval {CREATE TEMP TABLE t(l); PRAGMA journal_mode=off;}
569 do_execsql_test jrnlmode-9.2 {
570 PRAGMA locking_mode = exclusive;
572 PRAGMA journal_mode = off;