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 #***********************************************************************
12 # This file tests that the FTS5 'integrity-check' command detects
13 # inconsistencies (corruption) in the on-disk backing tables.
16 source [file join [file dirname [info script]] fts5_common.tcl]
17 set testprefix fts5corrupt
19 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
26 CREATE VIRTUAL TABLE t1 USING fts5(x);
27 INSERT INTO t1(t1, rank) VALUES('pgsz', 32);
32 for {set i 1} {$i < 200} {incr i} {
33 set doc [list [string repeat x $i] [string repeat y $i]]
34 execsql { INSERT INTO t1(rowid, x) VALUES($i, $doc) }
41 do_execsql_test 1.2 { INSERT INTO t1(t1) VALUES('integrity-check') }
42 set segid [lindex [fts5_level_segids t1] 0]
44 sqlite3_db_config db DEFENSIVE 0
47 DELETE FROM t1_data WHERE rowid = fts5_rowid('segment', $segid, 4);
49 catchsql { INSERT INTO t1(t1) VALUES('integrity-check') }
50 } {1 {database disk image is malformed}}
51 do_execsql_test 1.3b {
52 PRAGMA integrity_check(t1);
53 } {{malformed inverted index for FTS5 table main.t1}}
58 sqlite3_db_config db DEFENSIVE 0
60 UPDATE t1_data set block = X'00000000' || substr(block, 5) WHERE
61 rowid = fts5_rowid('segment', $segid, 4);
63 catchsql { INSERT INTO t1(t1) VALUES('integrity-check') }
64 } {1 {database disk image is malformed}}
67 #db eval {SELECT rowid, fts5_decode(rowid, block) aS r FROM t1_data} {puts $r}
70 #--------------------------------------------------------------------
73 CREATE VIRTUAL TABLE t2 USING fts5(x);
74 INSERT INTO t2(t2, rank) VALUES('pgsz', 64);
76 db func rnddoc fts5_rnddoc
78 for {set i 0} {$i < 500} {incr i} {
79 execsql { INSERT INTO t2 VALUES(rnddoc(50)) }
81 execsql { INSERT INTO t2(t2) VALUES('integrity-check') }
84 #--------------------------------------------------------------------
85 # A mundane test - missing row in the %_content table.
88 CREATE VIRTUAL TABLE t3 USING fts5(x);
89 INSERT INTO t3 VALUES('one o');
90 INSERT INTO t3 VALUES('two e');
91 INSERT INTO t3 VALUES('three o');
92 INSERT INTO t3 VALUES('four e');
93 INSERT INTO t3 VALUES('five o');
96 SELECT * FROM t3 WHERE t3 MATCH 'o'
97 } {{one o} {three o} {five o}}
98 sqlite3_db_config db DEFENSIVE 0
99 do_catchsql_test 3.1 {
100 DELETE FROM t3_content WHERE rowid = 3;
101 SELECT * FROM t3 WHERE t3 MATCH 'o';
102 } {1 {database disk image is malformed}}