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 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for the recover module, which can read
14 # through corrupt rows and pages.
18 # TODO(shess): These all test that the module correctly reads good
19 # data. It would be good to implement tests of corrupt data.
21 set testdir [file dirname $argv0]
22 source $testdir/tester.tcl
25 DROP TABLE IF EXISTS altered;
26 CREATE TABLE altered (
29 INSERT INTO altered VALUES ('a');
30 INSERT INTO altered VALUES ('b');
31 INSERT INTO altered VALUES ('c');
32 ALTER TABLE altered ADD COLUMN i INTEGER NOT NULL DEFAULT 10;
33 INSERT INTO altered VALUES ('d', 5);
36 # SQLite will fill the earlier rows with the default.
37 do_test recover-alter-1.0 {
38 execsql {SELECT c, i FROM altered ORDER BY rowid}
39 } {a 10 b 10 c 10 d 5}
41 # recover sees NULL for those rows.
42 do_test recover-alter-1.1 {
44 DROP TABLE IF EXISTS temp.altered_recover;
45 CREATE VIRTUAL TABLE temp.altered_recover USING recover(
51 execsql {SELECT c, i FROM altered_recover ORDER BY rowid}
52 } {a {} b {} c {} d 5}
54 # Can skip those NULL columns like if they contained a real NULL.
55 do_test recover-alter-1.2 {
57 DROP TABLE IF EXISTS temp.altered_recover;
58 CREATE VIRTUAL TABLE temp.altered_recover USING recover(
64 execsql {SELECT c, i FROM altered_recover ORDER BY rowid}
68 # It would be neat if this could work. I tried putting "DEFAULT ..."
69 # in the schema exposed by the recover table, but it doesn't do the
71 do_test recover-alter-1.2 {
73 DROP TABLE IF EXISTS temp.altered_recover;
74 CREATE VIRTUAL TABLE temp.altered_recover USING recover(
77 i INTEGER NOT NULL DEFAULT 10
80 execsql {SELECT c, i FROM altered_recover ORDER BY rowid}
81 } {a 10 b 10 c 10 d 5}
84 # Helper function to generate an arbitrarily-sized table.
85 proc generate {table base count} {
86 db eval "DROP TABLE IF EXISTS $table"
87 db transaction immediate {
88 db eval "CREATE TABLE $table (t TEXT,n INT)"
89 for {set i 0} {$i<$count} {incr i} {
90 set t [concat $base $i]
91 db eval [concat {INSERT INTO} $table {VALUES ($t, $i)}]
96 # Leaf-only database parses.
97 do_test recover-leaf-1.0 {
100 generate "leaf" "Leaf-node-generating line " 10
103 DROP TABLE IF EXISTS temp.leaf_recover;
104 CREATE VIRTUAL TABLE temp.leaf_recover USING recover(
110 execsql {SELECT t, n FROM leaf_recover ORDER BY rowid}
111 } {{Leaf-node-generating line 0} 0 {Leaf-node-generating line 1} 1 {Leaf-node-generating line 2} 2 {Leaf-node-generating line 3} 3 {Leaf-node-generating line 4} 4 {Leaf-node-generating line 5} 5 {Leaf-node-generating line 6} 6 {Leaf-node-generating line 7} 7 {Leaf-node-generating line 8} 8 {Leaf-node-generating line 9} 9}
113 # Single level of interior node.
114 do_test recover-interior-1.0 {
117 generate "interior" "Interior-node-generating line " 100
120 DROP TABLE IF EXISTS temp.interior_recover;
121 CREATE VIRTUAL TABLE temp.interior_recover USING recover(
127 execsql {SELECT t, n FROM interior_recover WHERE (rowid%10)=0 ORDER BY rowid}
128 } {{Interior-node-generating line 9} 9 {Interior-node-generating line 19} 19 {Interior-node-generating line 29} 29 {Interior-node-generating line 39} 39 {Interior-node-generating line 49} 49 {Interior-node-generating line 59} 59 {Interior-node-generating line 69} 69 {Interior-node-generating line 79} 79 {Interior-node-generating line 89} 89 {Interior-node-generating line 99} 99}
130 # Multiple levels of interior node.
131 do_test recover-interior-2.0 {
134 generate "interior2" "Interior-node-generating line " 5000
137 DROP TABLE IF EXISTS temp.interior2_recover;
138 CREATE VIRTUAL TABLE temp.interior2_recover USING recover(
144 execsql {SELECT t, n FROM interior2_recover WHERE (rowid%500)=0 ORDER BY rowid}
145 } {{Interior-node-generating line 499} 499 {Interior-node-generating line 999} 999 {Interior-node-generating line 1499} 1499 {Interior-node-generating line 1999} 1999 {Interior-node-generating line 2499} 2499 {Interior-node-generating line 2999} 2999 {Interior-node-generating line 3499} 3499 {Interior-node-generating line 3999} 3999 {Interior-node-generating line 4499} 4499 {Interior-node-generating line 4999} 4999}