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 #***********************************************************************
14 source [file join [file dirname [info script]] recover_common.tcl]
15 set testprefix recoverold
17 proc compare_result {db1 db2 sql} {
18 set r1 [$db1 eval $sql]
19 set r2 [$db2 eval $sql]
24 error "mismatch for $sql"
29 proc compare_dbs {db1 db2} {
30 compare_result $db1 $db2 "SELECT sql FROM sqlite_master ORDER BY 1"
31 foreach tbl [$db1 eval {SELECT name FROM sqlite_master WHERE type='table'}] {
32 compare_result $db1 $db2 "SELECT * FROM $tbl"
36 proc do_recover_test {tn {tsql {}} {res {}}} {
40 set R [sqlite3_recover_init db main test.db2]
41 $R config lostandfound lost_and_found
48 uplevel [list do_test $tn.1 [list compare_dbs db db2] {}]
50 uplevel [list do_execsql_test -db db2 $tn.1 $tsql $res]
58 set R [sqlite3_recover_init_sql db main my_sql_hook]
59 $R config lostandfound lost_and_found
64 db2 eval [join $::sqlhook ";"]
70 uplevel [list do_test $tn.sql [list compare_dbs db db2] {}]
72 uplevel [list do_execsql_test -db db2 $tn.sql $tsql $res]
77 proc my_sql_hook {sql} {
78 lappend ::sqlhook $sql
87 do_execsql_test 1.1.1 {
88 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
89 INSERT INTO t1 VALUES(1, 4, X'1234567800');
90 INSERT INTO t1 VALUES(2, 'test', 8.1);
91 INSERT INTO t1 VALUES(3, $doc, 8.4);
95 do_execsql_test 1.2.1 "
97 INSERT INTO t1 VALUES(13, 'hello\r\nworld', 13);
101 do_execsql_test 1.3.1 "
102 CREATE TABLE t2(i INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
103 INSERT INTO t2 VALUES(NULL, 1, 2);
104 INSERT INTO t2 VALUES(NULL, 3, 4);
105 INSERT INTO t2 VALUES(NULL, 5, 6);
106 CREATE TABLE t3(i INTEGER PRIMARY KEY AUTOINCREMENT, b, c);
107 INSERT INTO t3 VALUES(NULL, 1, 2);
108 INSERT INTO t3 VALUES(NULL, 3, 4);
109 INSERT INTO t3 VALUES(NULL, 5, 6);
112 do_recover_test 1.3.2
114 #-------------------------------------------------------------------------
116 do_execsql_test 2.1.0 {
117 PRAGMA auto_vacuum = 0;
118 CREATE TABLE t1(a, b, c, PRIMARY KEY(b, c)) WITHOUT ROWID;
119 INSERT INTO t1 VALUES(1, 2, 3);
120 INSERT INTO t1 VALUES(4, 5, 6);
121 INSERT INTO t1 VALUES(7, 8, 9);
124 do_recover_test 2.1.1
126 do_execsql_test 2.2.0 {
127 PRAGMA writable_schema = 1;
128 DELETE FROM sqlite_master WHERE name='t1';
130 do_recover_test 2.2.1 {
131 SELECT name FROM sqlite_master
134 do_execsql_test 2.3.0 {
135 CREATE TABLE lost_and_found(a, b, c);
137 do_recover_test 2.3.1 {
138 SELECT name FROM sqlite_master
139 } {lost_and_found lost_and_found_0}
141 do_execsql_test 2.4.0 {
142 CREATE TABLE lost_and_found_0(a, b, c);
144 do_recover_test 2.4.1 {
145 SELECT name FROM sqlite_master;
146 SELECT * FROM lost_and_found_1;
147 } {lost_and_found lost_and_found_0 lost_and_found_1
153 do_execsql_test 2.5 {
154 CREATE TABLE x1(a, b, c);
156 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100
158 INSERT INTO x1 SELECT i, i, hex(randomblob(500)) FROM s;
161 do_recover_test 2.5.1 {
162 SELECT name FROM sqlite_master;
163 SELECT * FROM lost_and_found_1;
164 } {lost_and_found lost_and_found_0 lost_and_found_1
170 ifcapable !secure_delete {
173 set R [sqlite3_recover_init db main test.db2]
174 $R config lostandfound lost_and_found
175 $R config freelistcorrupt 1
179 execsql { SELECT count(*) FROM lost_and_found_1; } db2
184 #-------------------------------------------------------------------------