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 / rbu / rbucorrupt.test

100 lines · 2256 bytes Raw Blame History
1# 2026 July 6
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]] rbu_common.tcl]
14if_no_rbu_support { finish_test ; return }
15set ::testprefix rbucorrupt
16
17catch {db close}
18sqlite3_shutdown
19sqlite3_config_lookaside 0 0
20sqlite3_initialize
21autoinstall_test_functions
22reset_db
23
24forcedelete rbu.db
25forcedelete state.db
26
27do_execsql_test 1.0 {
28 CREATE TABLE t1(id INTEGER PRIMARY KEY, a, b);
29 WITH s(i) AS (
30 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<63
31 )
32 INSERT INTO t1 SELECT i, i*10, 'row'||i FROM s;
33}
34
35sqlite3 db rbu.db
36do_execsql_test 1.1 {
37 CREATE TABLE data_t1(id INTEGER PRIMARY KEY, a, b, rbu_control);
38 WITH s(i) AS (
39 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<63
40 )
41 INSERT INTO data_t1 SELECT i, i*100, NULL, '.x.' FROM s;
42}
43
44db close
45
46do_test 1.2 {
47 sqlite3rbu rbu test.db rbu.db state.db
48 while {[rbu step]=="SQLITE_OK"} {
49 set st [rbu state]
50 if {$st=="checkpoint"} break
51 }
52 rbu close
53} {SQLITE_OK}
54
55do_test 1.3 {
56 sqlite3 db state.db
57 db eval { UPDATE rbu_state SET v=-1 WHERE k=4 }
58 db close
59} {}
60
61do_test 1.4 {
62 sqlite3rbu rbu test.db rbu.db state.db
63 rbu step
64 list [catch { rbu close } msg] $msg
65} {1 SQLITE_CORRUPT}
66
67#-------------------------------------------------------------------------
68reset_db
69forcedelete rbu.db
70forcedelete state.db
71
72do_test 2.0 {
73 for {set ii 0} {$ii<200} {incr ii} {
74 lappend cols "c$ii"
75 }
76 execsql "
77 CREATE TABLE t1(a INTEGER PRIMARY KEY, [join $cols ,]);
78 INSERT INTO t1(a, c0) VALUES(10, 100);
79 "
80} {}
81
82db close
83sqlite3 db rbu.db
84do_test 2.1 {
85 execsql "
86 CREATE TABLE data_t1(a INTEGER PRIMARY KEY, [join $cols ,], rbu_control);
87 INSERT INTO data_t1(a, c0, rbu_control) VALUES(10, 100, 'x');
88 "
89 db close
90} {}
91
92breakpoint
93do_test 2.2 {
94 sqlite3rbu rbu test.db rbu.db
95 while {[rbu step]=="SQLITE_OK"} {}
96 list [catch { rbu close } msg] $msg
97} {1 {SQLITE_ERROR - invalid rbu_control value}}
98
99
100finish_test