gitlab.com/CoiaPrant/sqlite3@v1.19.1/testdata/tcl/walpersist.test (about) 1 # 2011 July 26 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 # 12 # This file contains tests for using WAL with persistent WAL file mode. 13 # 14 15 set testdir [file dirname $argv0] 16 source $testdir/tester.tcl 17 source $testdir/lock_common.tcl 18 set ::testprefix walpersist 19 20 ifcapable !wal { 21 finish_test 22 return 23 } 24 25 do_test walpersist-1.0 { 26 db eval { 27 PRAGMA journal_mode=WAL; 28 CREATE TABLE t1(a); 29 INSERT INTO t1 VALUES(randomblob(5000)); 30 } 31 file exists test.db-wal 32 } {1} 33 do_test walpersist-1.1 { 34 file exists test.db-shm 35 } {1} 36 do_test walpersist-1.2 { 37 db close 38 list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm] 39 } {1 0 0} 40 do_test walpersist-1.3 { 41 sqlite3 db test.db 42 db eval {SELECT length(a) FROM t1} 43 } {5000} 44 do_test walpersist-1.4 { 45 list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm] 46 } {1 1 1} 47 do_test walpersist-1.5 { 48 file_control_persist_wal db -1 49 } {0 0} 50 do_test walpersist-1.6 { 51 file_control_persist_wal db 1 52 } {0 1} 53 do_test walpersist-1.7 { 54 file_control_persist_wal db -1 55 } {0 1} 56 do_test walpersist-1.8 { 57 file_control_persist_wal db 0 58 } {0 0} 59 do_test walpersist-1.9 { 60 file_control_persist_wal db -1 61 } {0 0} 62 do_test walpersist-1.10 { 63 file_control_persist_wal db 1 64 } {0 1} 65 do_test walpersist-1.11 { 66 db close 67 list [file exists test.db] [file exists test.db-wal] [file exists test.db-shm] 68 } {1 1 1} 69 70 # Make sure the journal_size_limit works to limit the size of the 71 # persisted wal file. In persistent-wal mode, any non-negative 72 # journal_size_limit causes the WAL file to be truncated to zero bytes 73 # when closing. 74 # 75 forcedelete test.db test.db-shm test.db-wal 76 do_test walpersist-2.1 { 77 sqlite3 db test.db 78 db eval { 79 PRAGMA journal_mode=WAL; 80 PRAGMA wal_autocheckpoint=OFF; 81 PRAGMA journal_size_limit=12000; 82 CREATE TABLE t1(x); 83 INSERT INTO t1 VALUES(randomblob(50000)); 84 UPDATE t1 SET x=randomblob(50000); 85 } 86 expr {[file size test.db-wal]>100000} 87 } {1} 88 do_test walpersist-2.2 { 89 file_control_persist_wal db 1 90 db close 91 concat [file exists test.db-wal] [file size test.db-wal] 92 } {1 0} 93 do_test walpersist-2.3 { 94 sqlite3 db test.db 95 execsql { PRAGMA integrity_check } 96 } {ok} 97 98 do_test 3.1 { 99 catch {db close} 100 forcedelete test.db test.db-shm test.db-wal 101 sqlite3 db test.db 102 execsql { 103 PRAGMA page_size = 1024; 104 PRAGMA journal_mode = WAL; 105 PRAGMA wal_autocheckpoint=128; 106 PRAGMA journal_size_limit=16384; 107 CREATE TABLE t1(a, b, PRIMARY KEY(a, b)); 108 } 109 } {wal 128 16384} 110 do_test 3.2 { 111 for {set i 0} {$i<200} {incr i} { 112 execsql { INSERT INTO t1 VALUES(randomblob(500), randomblob(500)) } 113 } 114 file_control_persist_wal db 1 115 db close 116 } {} 117 do_test walpersist-3.3 { 118 file size test.db-wal 119 } {0} 120 do_test walpersist-3.4 { 121 sqlite3 db test.db 122 execsql { PRAGMA integrity_check } 123 } {ok} 124 125 126 finish_test