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 # Test the shell tool ".ar" command.
16 set testdir [file dirname $argv0]
17 source $testdir/tester.tcl
18 set testprefix recover
23 set CLI [test_find_cli]
25 proc compare_result {db1 db2 sql} {
26 set r1 [$db1 eval $sql]
27 set r2 [$db2 eval $sql]
31 error "mismatch for $sql"
36 proc compare_dbs {db1 db2} {
37 compare_result $db1 $db2 "SELECT sql FROM sqlite_master ORDER BY 1"
38 foreach tbl [$db1 eval {SELECT name FROM sqlite_master WHERE type='table'}] {
39 compare_result $db1 $db2 "SELECT * FROM $tbl"
43 proc recover_with_opts {opts} {
44 set cmd ".recover $opts"
45 set fd [open [list |$::CLI test.db $cmd]]
46 fconfigure $fd -encoding binary
47 fconfigure $fd -translation binary
57 proc do_recover_test {tn {tsql {}} {res {}}} {
62 uplevel [list do_test $tn [list compare_dbs db db2] {}]
64 uplevel [list do_execsql_test -db db2 $tn $tsql $res]
73 do_execsql_test 1.1.1 {
74 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
75 INSERT INTO t1 VALUES(1, 4, X'1234567800');
76 INSERT INTO t1 VALUES(2, 'test', 8.1);
77 INSERT INTO t1 VALUES(3, $doc, 8.4);
81 do_execsql_test 1.2.1 "
83 INSERT INTO t1 VALUES(13, 'hello\r\nworld', 13);
87 do_execsql_test 1.3.1 "
88 CREATE TABLE t2(i INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
89 INSERT INTO t2 VALUES(NULL, 1, 2);
90 INSERT INTO t2 VALUES(NULL, 3, 4);
91 INSERT INTO t2 VALUES(NULL, 5, 6);
92 CREATE TABLE t3(i INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
93 INSERT INTO t3 VALUES(NULL, 1, 2);
94 INSERT INTO t3 VALUES(NULL, 3, 4);
95 INSERT INTO t3 VALUES(NULL, 5, 6);
100 #-------------------------------------------------------------------------
102 do_execsql_test 2.1.0 {
103 PRAGMA auto_vacuum = 0;
104 CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c)) WITHOUT ROWID;
105 INSERT INTO t1 VALUES(1, 2, 3);
106 INSERT INTO t1 VALUES(4, 5, 6);
107 INSERT INTO t1 VALUES(7, 8, 9);
110 do_recover_test 2.1.1
112 do_execsql_test 2.2.0 {
113 PRAGMA writable_schema = 1;
114 DELETE FROM sqlite_master WHERE name='t1';
116 do_recover_test 2.2.1 {
117 SELECT name FROM sqlite_master
120 do_execsql_test 2.3.0 {
121 CREATE TABLE lost_and_found(a, b, c);
123 do_recover_test 2.3.1 {
124 SELECT name FROM sqlite_master
125 } {lost_and_found lost_and_found_0}
127 do_execsql_test 2.4.0 {
128 CREATE TABLE lost_and_found_0(a, b, c);
130 do_recover_test 2.4.1 {
131 SELECT name FROM sqlite_master;
132 SELECT * FROM lost_and_found_1;
133 } {lost_and_found lost_and_found_0 lost_and_found_1
139 #-------------------------------------------------------------------------
143 #-------------------------------------------------------------------------
145 execsql { PRAGMA secure_delete = 0 }
146 execsql { PRAGMA auto_vacuum = 0 }
147 do_execsql_test 4.0 {
148 CREATE TABLE t1(a, b, c);
149 CREATE TABLE t2(d, e, f);
150 CREATE TABLE t3(g, h, i);
152 INSERT INTO t2 VALUES(1, 2, 3);
153 INSERT INTO t2 VALUES('a', 'b', 'c');
155 INSERT INTO t3 VALUES('one', 'two', 'three');
162 do_execsql_test -db db2 4.1.1 {
163 SELECT name FROM sqlite_schema
164 } {t3 lost_and_found}
165 do_execsql_test -db db2 4.1.2 {
166 SELECT id, c0, c1, c2 FROM lost_and_found
170 recover_with_opts -ignore-freelist
172 do_execsql_test -db db2 4.2.1 {
173 SELECT name FROM sqlite_schema
175 do_execsql_test -db db2 4.2.2 {