interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / recover / recoverfault.test

84 lines · 2152 bytes Raw Blame History
1# 2022 August 28
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11#
12
13source [file join [file dirname [info script]] recover_common.tcl]
14set testprefix recoverfault
15
16
17#--------------------------------------------------------------------------
18proc compare_result {db1 db2 sql} {
19 set r1 [$db1 eval $sql]
20 set r2 [$db2 eval $sql]
21 if {$r1 != $r2} {
22 puts "r1: $r1"
23 puts "r2: $r2"
24 error "mismatch for $sql"
25 }
26 return ""
27}
28
29proc 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"
33 }
34}
35#--------------------------------------------------------------------------
36
37do_execsql_test 1.0 {
38 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c);
39 INSERT INTO t1 VALUES(1, 2, 3);
40 INSERT INTO t1 VALUES(2, hex(randomblob(1000)), randomblob(2000));
41 CREATE INDEX i1 ON t1(b, c);
42 ANALYZE;
43}
44faultsim_save_and_close
45
46do_faultsim_test 1 -faults oom* -prep {
47 catch { db2 close }
48 faultsim_restore_and_reopen
49} -body {
50 set R [sqlite3_recover_init db main test.db2]
51 $R run
52 $R finish
53} -test {
54 faultsim_test_result {0 {}} {1 {}}
55 if {$testrc==0} {
56 sqlite3 db2 test.db2
57 compare_dbs db db2
58 db2 close
59 }
60}
61
62faultsim_restore_and_reopen
63do_execsql_test 2.0 {
64 CREATE TABLE t2(a INTEGER PRIMARY KEY, b, c);
65 INSERT INTO t2 VALUES(1, 2, 3);
66 INSERT INTO t2 VALUES(2, hex(randomblob(1000)), hex(randomblob(2000)));
67 PRAGMA writable_schema = 1;
68 DELETE FROM sqlite_schema WHERE name='t2';
69}
70faultsim_save_and_close
71
72do_faultsim_test 2 -faults oom* -prep {
73 faultsim_restore_and_reopen
74} -body {
75 set R [sqlite3_recover_init db main test.db2]
76 $R config lostandfound lost_and_found
77 $R run
78 $R finish
79} -test {
80 faultsim_test_result {0 {}} {1 {}}
81}
82
83finish_test
84