sl@0: # 2008 April 17 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. The focus sl@0: # of these tests is the journal mode pragma. sl@0: # sl@0: # $Id: jrnlmode.test,v 1.6 2008/09/26 21:08:08 drh Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable {!pager_pragmas} { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: #---------------------------------------------------------------------- sl@0: # Test cases jrnlmode-1.X test the PRAGMA logic. sl@0: # sl@0: do_test jrnlmode-1.0 { sl@0: execsql { sl@0: PRAGMA journal_mode; sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: } sl@0: } [list delete delete delete] sl@0: do_test jrnlmode-1.1 { sl@0: execsql { sl@0: PRAGMA journal_mode = persist; sl@0: } sl@0: } {persist} sl@0: do_test jrnlmode-1.2 { sl@0: execsql { sl@0: PRAGMA journal_mode; sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: } sl@0: } [list persist persist persist] sl@0: do_test jrnlmode-1.4 { sl@0: execsql { sl@0: PRAGMA journal_mode = off; sl@0: } sl@0: } {off} sl@0: do_test jrnlmode-1.5 { sl@0: execsql { sl@0: PRAGMA journal_mode; sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: } sl@0: } {off off off} sl@0: do_test jrnlmode-1.6 { sl@0: execsql { sl@0: PRAGMA journal_mode = delete; sl@0: } sl@0: } {delete} sl@0: do_test jrnlmode-1.7 { sl@0: execsql { sl@0: PRAGMA journal_mode; sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: } sl@0: } {delete delete delete} sl@0: do_test jrnlmode-1.7.1 { sl@0: execsql { sl@0: PRAGMA journal_mode = truncate; sl@0: } sl@0: } {truncate} sl@0: do_test jrnlmode-1.7.2 { sl@0: execsql { sl@0: PRAGMA journal_mode; sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: } sl@0: } {truncate truncate truncate} sl@0: do_test jrnlmode-1.8 { sl@0: execsql { sl@0: PRAGMA journal_mode = off; sl@0: PRAGMA journal_mode = invalid; sl@0: } sl@0: } {off off} sl@0: ifcapable attach { sl@0: do_test jrnlmode-1.9 { sl@0: execsql { sl@0: PRAGMA journal_mode = PERSIST; sl@0: ATTACH ':memory:' as aux1; sl@0: } sl@0: execsql { sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA aux1.journal_mode; sl@0: } sl@0: } {persist persist} sl@0: do_test jrnlmode-1.10 { sl@0: execsql { sl@0: PRAGMA main.journal_mode = OFF; sl@0: } sl@0: execsql { sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: PRAGMA aux1.journal_mode; sl@0: } sl@0: } {off persist persist} sl@0: do_test jrnlmode-1.11 { sl@0: execsql { sl@0: PRAGMA journal_mode; sl@0: } sl@0: } {persist} sl@0: do_test jrnlmode-1.12 { sl@0: execsql { sl@0: ATTACH ':memory:' as aux2; sl@0: } sl@0: execsql { sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA aux1.journal_mode; sl@0: PRAGMA aux2.journal_mode; sl@0: } sl@0: } {off persist persist} sl@0: do_test jrnlmode-1.11 { sl@0: execsql { sl@0: PRAGMA aux1.journal_mode = DELETE; sl@0: } sl@0: execsql { sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA aux1.journal_mode; sl@0: PRAGMA aux2.journal_mode; sl@0: } sl@0: } {off delete persist} sl@0: do_test jrnlmode-1.12 { sl@0: execsql { sl@0: PRAGMA journal_mode = delete; sl@0: } sl@0: execsql { sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: PRAGMA aux1.journal_mode; sl@0: PRAGMA aux2.journal_mode; sl@0: } sl@0: } {delete delete delete delete} sl@0: do_test jrnlmode-1.13 { sl@0: execsql { sl@0: ATTACH ':memory:' as aux3; sl@0: } sl@0: execsql { sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: PRAGMA aux1.journal_mode; sl@0: PRAGMA aux2.journal_mode; sl@0: PRAGMA aux3.journal_mode; sl@0: } sl@0: } {delete delete delete delete delete} sl@0: do_test jrnlmode-1.14 { sl@0: execsql { sl@0: PRAGMA journal_mode = TRUNCATE; sl@0: } sl@0: execsql { sl@0: PRAGMA main.journal_mode; sl@0: PRAGMA temp.journal_mode; sl@0: PRAGMA aux1.journal_mode; sl@0: PRAGMA aux2.journal_mode; sl@0: PRAGMA aux3.journal_mode; sl@0: } sl@0: } {truncate truncate truncate truncate truncate} sl@0: sl@0: do_test jrnlmode-1.99 { sl@0: execsql { sl@0: DETACH aux1; sl@0: DETACH aux2; sl@0: DETACH aux3; sl@0: } sl@0: } {} sl@0: } sl@0: sl@0: ifcapable attach { sl@0: file delete -force test2.db sl@0: do_test jrnlmode-2.1 { sl@0: execsql { sl@0: ATTACH 'test2.db' AS aux; sl@0: PRAGMA main.journal_mode = persist; sl@0: PRAGMA aux.journal_mode = persist; sl@0: CREATE TABLE abc(a, b, c); sl@0: CREATE TABLE aux.def(d, e, f); sl@0: } sl@0: execsql { sl@0: BEGIN; sl@0: INSERT INTO abc VALUES(1, 2, 3); sl@0: INSERT INTO def VALUES(4, 5, 6); sl@0: COMMIT; sl@0: } sl@0: list [file exists test.db-journal] [file exists test2.db-journal] sl@0: } {1 1} sl@0: sl@0: do_test jrnlmode-2.2 { sl@0: file size test.db-journal sl@0: } {0} sl@0: sl@0: do_test jrnlmode-2.3 { sl@0: execsql { sl@0: SELECT * FROM abc; sl@0: } sl@0: } {1 2 3} sl@0: sl@0: do_test jrnlmode-2.4 { sl@0: file size test.db-journal sl@0: } {0} sl@0: sl@0: do_test jrnlmode-2.5 { sl@0: execsql { sl@0: SELECT * FROM def; sl@0: } sl@0: } {4 5 6} sl@0: sl@0: #---------------------------------------------------------------------- sl@0: # Test caes jrnlmode-3.X verify that ticket #3127 has been fixed. sl@0: # sl@0: db close sl@0: file delete -force test2.db sl@0: file delete -force test.db sl@0: sqlite3 db test.db sl@0: sl@0: do_test jrnlmode-3.1 { sl@0: execsql { sl@0: CREATE TABLE x(n INTEGER); sl@0: ATTACH 'test2.db' AS a; sl@0: create table a.x ( n integer ); sl@0: insert into a.x values(1); sl@0: insert into a.x values (2); sl@0: insert into a.x values (3); sl@0: insert into a.x values (4); sl@0: } sl@0: } {} sl@0: sl@0: do_test jrnlmode-3.2 { sl@0: execsql { PRAGMA journal_mode=off; } sl@0: execsql { sl@0: BEGIN IMMEDIATE; sl@0: INSERT OR IGNORE INTO main.x SELECT * FROM a.x; sl@0: COMMIT; sl@0: } sl@0: } {} sl@0: } sl@0: sl@0: ifcapable autovacuum&&pragma { sl@0: db close sl@0: file delete -force test.db sl@0: sqlite3 db test.db sl@0: do_test jrnlmode-4.1 { sl@0: execsql { sl@0: PRAGMA cache_size = 1; sl@0: PRAGMA auto_vacuum = 1; sl@0: CREATE TABLE abc(a, b, c); sl@0: } sl@0: execsql { PRAGMA page_count } sl@0: } {3} sl@0: sl@0: do_test jrnlmode-4.2 { sl@0: execsql { PRAGMA journal_mode = off } sl@0: } {off} sl@0: sl@0: do_test jrnlmode-4.3 { sl@0: execsql { INSERT INTO abc VALUES(1, 2, randomblob(2000)) } sl@0: } {} sl@0: sl@0: # This will attempt to truncate the database file. Check that this sl@0: # is not a problem when journal_mode=off. sl@0: do_test jrnlmode-4.4 { sl@0: execsql { DELETE FROM abc } sl@0: } {} sl@0: sl@0: integrity_check jrnlmode-4.5 sl@0: } sl@0: sl@0: #------------------------------------------------------------------------ sl@0: # The following test caes, jrnlmode-5.*, test the journal_size_limit sl@0: # pragma. sl@0: ifcapable pragma { sl@0: db close sl@0: file delete -force test.db test2.db test3.db sl@0: sqlite3 db test.db sl@0: sl@0: do_test jrnlmode-5.1 { sl@0: execsql {pragma page_size=1024} sl@0: execsql {pragma journal_mode=persist} sl@0: } {persist} sl@0: sl@0: do_test jrnlmode-5.2 { sl@0: execsql { PRAGMA journal_size_limit } sl@0: } {-1} sl@0: do_test jrnlmode-5.3 { sl@0: execsql { sl@0: ATTACH 'test2.db' AS aux; sl@0: PRAGMA aux.journal_size_limit; sl@0: } sl@0: } {-1} sl@0: do_test jrnlmode-5.4 { sl@0: execsql { PRAGMA aux.journal_size_limit = 10240 } sl@0: } {10240} sl@0: do_test jrnlmode-5.5 { sl@0: execsql { PRAGMA main.journal_size_limit = 20480 } sl@0: } {20480} sl@0: do_test jrnlmode-5.6 { sl@0: execsql { PRAGMA journal_size_limit } sl@0: } {20480} sl@0: do_test jrnlmode-5.7 { sl@0: execsql { PRAGMA aux.journal_size_limit } sl@0: } {10240} sl@0: sl@0: do_test jrnlmode-5.8 { sl@0: execsql { ATTACH 'test3.db' AS aux2 } sl@0: } {} sl@0: sl@0: do_test jrnlmode-5.9 { sl@0: execsql { sl@0: CREATE TABLE main.t1(a, b, c); sl@0: CREATE TABLE aux.t2(a, b, c); sl@0: CREATE TABLE aux2.t3(a, b, c); sl@0: } sl@0: } {} sl@0: do_test jrnlmode-5.10 { sl@0: list \ sl@0: [file exists test.db-journal] \ sl@0: [file exists test2.db-journal] \ sl@0: [file exists test3.db-journal] sl@0: } {1 1 1} sl@0: do_test jrnlmode-5.11 { sl@0: execsql { sl@0: BEGIN; sl@0: INSERT INTO t3 VALUES(randomblob(1000),randomblob(1000),randomblob(1000)); sl@0: INSERT INTO t3 sl@0: SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; sl@0: INSERT INTO t3 sl@0: SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; sl@0: INSERT INTO t3 sl@0: SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; sl@0: INSERT INTO t3 sl@0: SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; sl@0: INSERT INTO t3 sl@0: SELECT randomblob(1000),randomblob(1000),randomblob(1000) FROM t3; sl@0: INSERT INTO t2 SELECT * FROM t3; sl@0: INSERT INTO t1 SELECT * FROM t2; sl@0: COMMIT; sl@0: } sl@0: list \ sl@0: [file exists test.db-journal] \ sl@0: [file exists test2.db-journal] \ sl@0: [file exists test3.db-journal] \ sl@0: [file size test.db-journal] \ sl@0: [file size test2.db-journal] \ sl@0: [file size test3.db-journal] sl@0: } {1 1 1 0 0 0} sl@0: sl@0: do_test jrnlmode-5.12 { sl@0: execsql { sl@0: BEGIN; sl@0: UPDATE t1 SET a = randomblob(1000); sl@0: } sl@0: expr {[file size test.db-journal]>30000} sl@0: } {1} sl@0: do_test jrnlmode-5.13 { sl@0: execsql COMMIT sl@0: file size test.db-journal sl@0: } {20480} sl@0: sl@0: do_test jrnlmode-5.14 { sl@0: execsql { sl@0: BEGIN; sl@0: UPDATE t2 SET a = randomblob(1000); sl@0: } sl@0: expr {[file size test2.db-journal]>30000} sl@0: } {1} sl@0: do_test jrnlmode-5.15 { sl@0: execsql COMMIT sl@0: file size test2.db-journal sl@0: } {10240} sl@0: sl@0: do_test jrnlmode-5.16 { sl@0: execsql { sl@0: BEGIN; sl@0: UPDATE t3 SET a = randomblob(1000); sl@0: } sl@0: set journalsize [file size test3.db-journal] sl@0: expr {$journalsize>30000} sl@0: } {1} sl@0: do_test jrnlmode-5.17 { sl@0: execsql COMMIT sl@0: set sz [file size test3.db-journal] sl@0: expr {$sz>=$journalsize} sl@0: } {1} sl@0: sl@0: do_test jrnlmode-5.18 { sl@0: execsql { sl@0: PRAGMA journal_size_limit = -4; sl@0: BEGIN; sl@0: UPDATE t1 SET a = randomblob(1000); sl@0: } sl@0: set journalsize [file size test.db-journal] sl@0: expr {$journalsize>30000} sl@0: } {1} sl@0: do_test jrnlmode-5.19 { sl@0: execsql COMMIT sl@0: set sz [file size test.db-journal] sl@0: expr {$sz>=$journalsize} sl@0: } {1} sl@0: } sl@0: sl@0: finish_test