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 #***********************************************************************
13 if {![info exists testdir
]} {
14 set testdir
[file join [file dirname
[info script
]] .. .. test
]
16 source $testdir/tester.tcl
18 proc if_no_rbu_support
{tcl
} {
20 ifcapable
!rbu
{ set bOk
0 }
21 if {[permutation
]=="journaltest"} { set bOk
0 }
23 set c
[catch {uplevel 1 $tcl} r
]
28 proc check_prestep_state
{target state
} {
29 set oal_exists
[file exists
$target-oal
]
30 set wal_exists
[file exists
$target-wal
]
31 set progress
[rbu progress
]
33 if {($progress==0 && $state!="oal" && $state!="done")
34 ||
($oal_exists && $wal_exists)
35 ||
($progress>0 && $state=="oal" && (!$oal_exists ||
$wal_exists))
36 ||
($state=="move" && (!$oal_exists ||
$wal_exists))
37 ||
($state=="checkpoint" && ($oal_exists ||
!$wal_exists))
38 ||
($state=="done" && ($oal_exists && $progress!=0))
40 error "B: state=$state progress=$progress oal=$oal_exists wal=$wal_exists"
44 proc check_poststep_state
{rc target state
} {
45 if {$rc=="SQLITE_OK" ||
$rc=="SQLITE_DONE"} {
46 set oal_exists
[file exists
$target-oal
]
47 set wal_exists
[file exists
$target-wal
]
48 if {$state=="move" && ($oal_exists ||
!$wal_exists)} {
49 error "A: state=$state progress=$progress oal=$oal_exists wal=$wal_exists"
54 # Run the RBU in file $rbu on target database $target until completion.
56 proc run_rbu
{target rbu
} {
57 sqlite3rbu rbu
$target $rbu
61 check_prestep_state
$target $state
63 check_poststep_state
$rc $target $state
65 if {$rc!="SQLITE_OK"} break
70 proc step_rbu
{target rbu
} {
72 sqlite3rbu rbu
$target $rbu
74 check_prestep_state
$target $state
76 check_poststep_state
$rc $target $state
78 if {$rc != "SQLITE_OK"} break
83 proc step_rbu_legacy
{target rbu
} {
85 sqlite3rbu rbu
$target $rbu
87 check_prestep_state
$target $state
89 check_poststep_state
$rc $target $state
91 if {$rc != "SQLITE_OK"} break
93 tmpdb
eval { DELETE FROM rbu_state WHERE k
==10 }
99 proc do_rbu_vacuum_test
{tn step
{statedb state.db
}} {
101 if {$statedb=="" && $step==1} breakpoint
102 uplevel [list do_test
$tn.1 [string map
[list %state
% $statedb %step
% $step] {
103 if {%step
%==0} { sqlite3rbu_vacuum rbu test.db
{%state
%}}
105 if {%step
%==1} { sqlite3rbu_vacuum rbu test.db
{%state
%}}
106 set state
[rbu state
]
107 check_prestep_state test.db
$state
109 check_poststep_state
$rc test.db
$state
110 if {$rc!="SQLITE_OK"} break
111 if {%step
%==1} { rbu
close }
116 uplevel [list do_execsql_test
$tn.2 {
117 PRAGMA integrity_check