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 / fts5 / test / fts5corrupt8.test

147 lines · 3251 bytes Raw Blame History
1# 2024 Aug 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]] fts5_common.tcl]
14set testprefix fts5corrupt8
15
16# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
17ifcapable !fts5 {
18 finish_test
19 return
20}
21
22do_execsql_test 1.0 {
23 CREATE VIRTUAL TABLE t1 USING fts5(x);
24}
25
26do_execsql_test 1.1 {
27 UPDATE t1_data SET block='hello world' WHERE id=10
28}
29
30db close
31sqlite3 db test.db
32
33do_catchsql_test 1.2 {
34 SELECT * FROM t1
35} {1 {fts5: corrupt structure record for table "t1"}}
36do_catchsql_test 1.3 {
37 DROP TABLE t1
38} {0 {}}
39do_execsql_test 1.4 {
40 SELECT * FROM sqlite_schema
41}
42
43do_execsql_test 2.0 {
44 CREATE VIRTUAL TABLE t1 USING fts5(x);
45}
46do_execsql_test 2.1 {
47 UPDATE t1_config SET v=555 WHERE k='version'
48}
49db close
50sqlite3 db test.db
51do_catchsql_test 2.2 {
52 SELECT * FROM t1
53} {1 {invalid fts5 file format (found 555, expected 4 or 5) - run 'rebuild'}}
54do_catchsql_test 2.3 {
55 DROP TABLE t1
56} {1 {invalid fts5 file format (found 555, expected 4 or 5) - run 'rebuild'}}
57do_test 2.4 {
58 sqlite3_fts5_drop_corrupt_table db main t1
59} {}
60do_execsql_test 2.5 {
61 SELECT * FROM sqlite_schema
62}
63
64do_execsql_test 3.0 {
65 CREATE VIRTUAL TABLE t1 USING fts5(x);
66}
67do_execsql_test 3.1 {
68 DELETE FROM t1_config;
69}
70db close
71sqlite3 db test.db
72do_catchsql_test 3.2 {
73 SELECT * FROM t1
74} {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}}
75do_catchsql_test 3.3 {
76 DROP TABLE t1
77} {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}}
78
79
80do_test 3.4 {
81 sqlite3_db_config db DEFENSIVE 1
82} {1}
83do_test 3.5 {
84 sqlite3_fts5_drop_corrupt_table db main t1
85} {}
86do_test 3.6 {
87 sqlite3_db_config db DEFENSIVE -1
88} {1}
89do_execsql_test 3.7 {
90 SELECT * FROM sqlite_schema
91}
92
93#-------------------------------------------------------------------------
94reset_db
95
96proc hex_to_blob {hex} {
97 binary encode hex $hex
98}
99db func hex_to_blob hex_to_blob
100
101do_execsql_test 4.0 {
102 CREATE VIRTUAL TABLE x1 USING fts5(x, content='', contentless_delete=1);
103 BEGIN;
104 INSERT INTO x1(rowid, x) VALUES(1, 'a b c d e f g h');
105 INSERT INTO x1(rowid, x) VALUES(2, 'a b c d e f g h');
106 COMMIT;
107 DELETE FROM x1 WHERE rowid=1;
108}
109
110do_execsql_test 4.1 {
111 SELECT hex(block) FROM x1_data WHERE id=10
112} {
113 00000000FF00000101010200010101010101010102
114}
115
116do_execsql_test 4.2.1 {
117 UPDATE x1_data SET block=
118 X'00000000FF00000101010200010101010101819C9B95A8000102'
119 WHERE id=10;
120}
121
122do_catchsql_test 4.2.2 {
123 SELECT * FROM x1('c d e');
124} {1 {out of memory}}
125
126do_execsql_test 4.3.1 {
127 UPDATE x1_data SET block=
128 X'00000000FF000001010102000101010101019282AFF9A0000102'
129 WHERE id=10;
130}
131
132do_catchsql_test 4.3.2 {
133 SELECT * FROM x1('c d e');
134} {1 {out of memory}}
135
136do_execsql_test 4.4.1 {
137 UPDATE x1_data SET block=
138 X'00000000FF000001010102000101010101018181808080130102'
139 WHERE id=10;
140}
141
142do_catchsql_test 4.3.2 {
143 SELECT * FROM x1('c d e');
144} {1 {out of memory}}
145
146finish_test
147