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 source [file join [file dirname [info script]] rbu_common.tcl]
14 if_no_rbu_support { finish_test ; return }
15 set ::testprefix rbumisc
17 proc populate_rbu_db {} {
21 CREATE TABLE data_x1(a, b, c, rbu_control);
22 INSERT INTO data_x1 VALUES(1, 1, 1, 0);
23 INSERT INTO data_x1 VALUES(2, 2, 2, 0);
25 CREATE TABLE dat(a, b, c, rbu_control);
26 CREATE TABLE "data x1"(a, b, c, rbu_control);
27 CREATE TABLE datax1(a, b, c, rbu_control);
28 CREATE TABLE data_(a, b, c, rbu_control);
30 INSERT INTO "data x1" VALUES(3, 3, 3, 0);
31 INSERT INTO datax1 VALUES(3, 3, 3, 0);
32 INSERT INTO data_ VALUES(3, 3, 3, 0);
33 INSERT INTO dat VALUES(3, 3, 3, 0);
38 #-------------------------------------------------------------------------
39 # Ensure that RBU is not confused by oddly named tables in an RBU
43 CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY);
50 step_rbu test.db rbu.db
51 db eval { SELECT * FROM x1 }
55 db eval { DELETE FROM x1 }
57 rbu eval { DELETE FROM rbu_state }
59 step_rbu test.db rbu.db
60 db eval { SELECT * FROM x1 }
64 db eval { DELETE FROM x1 }
67 sqlite3rbu rbu test.db rbu.db
72 forcecopy test.db-oal test.db-wal
73 sqlite3rbu rbu test.db rbu.db
75 list [catch { rbu close } msg] $msg
76 } {1 {SQLITE_ERROR - cannot update wal mode database}}
78 #-------------------------------------------------------------------------
79 # Test the effect of a wal file appearing after the target database has
80 # been opened, but before it has been locked.
83 testvfs tvfs -default 1
85 for {set N 1} {$N < 10} {incr N} {
88 do_execsql_test 2.$N.0 {
89 CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY);
94 sqlite3rbu rbu test.db rbu.db
103 proc xAccess {method file args} {
105 if {[file tail $file]=="test.db-wal"} {
107 if {$nAccessCnt==0} {
108 set fd [open test.db-wal w]
109 puts -nonewline $fd [string repeat 0 2000]
117 {1 {SQLITE_ERROR - cannot update wal mode database}}
119 {1 {SQLITE_CANTOPEN - unable to open database file}}
125 set res [list [catch {
126 sqlite3rbu rbu test.db rbu.db
137 #-------------------------------------------------------------------------
138 testvfs tvfs -default 1
141 do_execsql_test 3.0 {
142 CREATE TABLE x1(a, b, c INTEGER PRIMARY KEY);
145 tvfs script xFileControl
146 tvfs filter xFileControl
148 proc xFileControl {method file verb args} {
149 if {$verb=="ZIPVFS" && [info exists ::zipvfs_filecontrol]} {
150 return $::zipvfs_filecontrol
152 return "SQLITE_NOTFOUND"
156 foreach {tn ret err} {
162 set ::zipvfs_filecontrol $ret
165 sqlite3rbu rbu test.db rbu.db
174 #-------------------------------------------------------------------------