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 # Test the shell tool ".ar" command.
15 set testdir [file dirname $argv0]
16 source $testdir/tester.tcl
17 set testprefix recover
22 set CLI [test_find_cli]
24 proc compare_result {db1 db2 sql} {
25 set r1 [$db1 eval $sql]
26 set r2 [$db2 eval $sql]
30 error "mismatch for $sql"
35 proc compare_dbs {db1 db2} {
36 compare_result $db1 $db2 "SELECT sql FROM sqlite_master ORDER BY 1"
37 foreach tbl [$db1 eval {SELECT name FROM sqlite_master WHERE type='table'}] {
38 compare_result $db1 $db2 "SELECT * FROM $tbl"
42 proc recover_with_opts {opts} {
43 set cmd ".recover $opts"
44 set fd [open [list |$::CLI test.db $cmd]]
45 fconfigure $fd -encoding binary
46 fconfigure $fd -translation binary
56 proc do_recover_test {tn {tsql {}} {res {}}} {
61 uplevel [list do_test $tn [list compare_dbs db db2] {}]
63 uplevel [list do_execsql_test -db db2 $tn $tsql $res]
72 do_execsql_test 1.1.1 {
73 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
74 INSERT INTO t1 VALUES(1, 4, X'1234567800');
75 INSERT INTO t1 VALUES(2, 'test', 8.1);
76 INSERT INTO t1 VALUES(3, $doc, 8.4);
80 do_execsql_test 1.2.1 "
82 INSERT INTO t1 VALUES(13, 'hello\r\nworld', 13);
86 do_execsql_test 1.3.1 "
87 CREATE TABLE t2(i INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
88 INSERT INTO t2 VALUES(NULL, 1, 2);
89 INSERT INTO t2 VALUES(NULL, 3, 4);
90 INSERT INTO t2 VALUES(NULL, 5, 6);
91 CREATE TABLE t3(i INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
92 INSERT INTO t3 VALUES(NULL, 1, 2);
93 INSERT INTO t3 VALUES(NULL, 3, 4);
94 INSERT INTO t3 VALUES(NULL, 5, 6);
99 #-------------------------------------------------------------------------
101 do_execsql_test 2.1.0 {
102 PRAGMA auto_vacuum = 0;
103 CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c)) WITHOUT ROWID;
104 INSERT INTO t1 VALUES(1, 2, 3);
105 INSERT INTO t1 VALUES(4, 5, 6);
106 INSERT INTO t1 VALUES(7, 8, 9);
109 do_recover_test 2.1.1
111 do_execsql_test 2.2.0 {
112 PRAGMA writable_schema = 1;
113 DELETE FROM sqlite_master WHERE name='t1';
115 do_recover_test 2.2.1 {
116 SELECT name FROM sqlite_master
119 do_execsql_test 2.3.0 {
120 CREATE TABLE lost_and_found(a, b, c);
122 do_recover_test 2.3.1 {
123 SELECT name FROM sqlite_master
124 } {lost_and_found lost_and_found_0}
126 do_execsql_test 2.4.0 {
127 CREATE TABLE lost_and_found_0(a, b, c);
129 do_recover_test 2.4.1 {
130 SELECT name FROM sqlite_master;
131 SELECT * FROM lost_and_found_1;
132 } {lost_and_found lost_and_found_0 lost_and_found_1
138 #-------------------------------------------------------------------------
142 #-------------------------------------------------------------------------
144 execsql { PRAGMA secure_delete = 0 }
145 execsql { PRAGMA auto_vacuum = 0 }
146 do_execsql_test 4.0 {
147 CREATE TABLE t1(a, b, c);
148 CREATE TABLE t2(d, e, f);
149 CREATE TABLE t3(g, h, i);
151 INSERT INTO t2 VALUES(1, 2, 3);
152 INSERT INTO t2 VALUES('a', 'b', 'c');
154 INSERT INTO t3 VALUES('one', 'two', 'three');
161 do_execsql_test -db db2 4.1.1 {
162 SELECT name FROM sqlite_schema
163 } {t3 lost_and_found}
164 do_execsql_test -db db2 4.1.2 {
165 SELECT id, c0, c1, c2 FROM lost_and_found
169 recover_with_opts -ignore-freelist
171 do_execsql_test -db db2 4.2.1 {
172 SELECT name FROM sqlite_schema
174 do_execsql_test -db db2 4.2.2 {