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 / recoverfault2.test

102 lines · 2329 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 recoverfault2
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);
39 INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n');
40"
41faultsim_save_and_close
42
43proc my_sql_hook {sql} {
44 lappend ::lSql $sql
45 return 0
46}
47
48do_faultsim_test 1 -faults oom* -prep {
49 catch { db2 close }
50 faultsim_restore_and_reopen
51 set ::lSql [list]
52} -body {
53 set R [sqlite3_recover_init_sql db main my_sql_hook]
54 $R run
55 $R finish
56} -test {
57 faultsim_test_result {0 {}} {1 {}}
58 if {$testrc==0} {
59 sqlite3 db2 ""
60 db2 eval [join $::lSql ";"]
61 compare_dbs db db2
62 db2 close
63 }
64}
65
66ifcapable utf16 {
67 reset_db
68 do_execsql_test 2.0 "
69 PRAGMA encoding='utf-16';
70 CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
71 INSERT INTO t1 VALUES(2, '\012hello\015world\012today\n');
72 "
73 faultsim_save_and_close
74
75 proc my_sql_hook {sql} {
76 lappend ::lSql $sql
77 return 0
78 }
79
80 do_faultsim_test 2 -faults oom-t* -prep {
81 catch { db2 close }
82 faultsim_restore_and_reopen
83 set ::lSql [list]
84 } -body {
85 set R [sqlite3_recover_init_sql db main my_sql_hook]
86 $R run
87 $R finish
88 } -test {
89 faultsim_test_result {0 {}} {1 {}}
90 if {$testrc==0} {
91 sqlite3 db2 ""
92 db2 eval [join $::lSql ";"]
93 compare_dbs db db2
94 db2 close
95 }
96 }
97}
98
99
100
101finish_test
102