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 #***********************************************************************
12 # This file implements tests of the SQLITE_IOCAP_POWERSAFE_OVERWRITE property
13 # and the SQLITE_FCNTL_POWERSAFE_OVERWRITE file-control for manipulating it.
15 # The name of this file comes from the fact that we used to call the
16 # POWERSAFE_OVERWRITE property ZERO_DAMAGE.
19 set testdir [file dirname $argv0]
20 source $testdir/tester.tcl
21 set testprefix zerodamage
28 # POWERSAFE_OVERWRITE defaults to true
30 do_test zerodamage-1.0 {
31 file_control_powersafe_overwrite db -1
34 # Check the ability to turn zero-damage on and off.
36 do_test zerodamage-1.1 {
37 file_control_powersafe_overwrite db 0
38 file_control_powersafe_overwrite db -1
40 do_test zerodamage-1.2 {
41 file_control_powersafe_overwrite db 1
42 file_control_powersafe_overwrite db -1
45 # Run a transaction with zero-damage on, a small page size and a much larger
46 # sectorsize. Verify that the maximum journal size is small - that the
47 # rollback journal is not being padded.
49 do_test zerodamage-2.0 {
53 sqlite3 db file:test.db?psow=TRUE -uri 1
54 unset -nocomplain ::max_journal_size
55 set ::max_journal_size 0
56 proc xDeleteCallback {method file args} {
57 set sz [file size $file]
58 if {$sz>$::max_journal_size} {set ::max_journal_size $sz}
61 tv script xDeleteCallback
62 load_static_extension db wholenumber
64 PRAGMA page_size=1024;
65 PRAGMA journal_mode=DELETE;
67 CREATE VIRTUAL TABLE nums USING wholenumber;
68 CREATE TABLE t1(x, y);
69 INSERT INTO t1 SELECT value, randomblob(100) FROM nums
70 WHERE value BETWEEN 1 AND 400;
72 set ::max_journal_size 0
74 UPDATE t1 SET y=randomblob(50) WHERE x=123;
76 concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
79 # Repeat the previous step with zero-damage turned off. This time the
80 # maximum rollback journal size should be much larger.
82 do_test zerodamage-2.1 {
83 set ::max_journal_size 0
85 sqlite3 db file:test.db?psow=FALSE -uri 1
87 UPDATE t1 SET y=randomblob(50) WHERE x=124;
89 concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
93 # Run a WAL-mode transaction with POWERSAFE_OVERWRITE on to verify that the
94 # WAL file does not get too big.
96 do_test zerodamage-3.0 {
98 PRAGMA journal_mode=WAL;
101 sqlite3 db file:test.db?psow=TRUE -uri 1
103 UPDATE t1 SET y=randomblob(50) WHERE x=124;
105 file size test.db-wal
108 # Repeat the previous with POWERSAFE_OVERWRITE off. Verify that the WAL file
111 do_test zerodamage-3.1 {
113 sqlite3 db file:test.db?psow=FALSE -uri 1
115 UPDATE t1 SET y=randomblob(50) WHERE x=124;
117 file size test.db-wal