Debian Codegraph @

ext/fts5/test/fts5corrupt6.test

raw
1 # 2015 Apr 24
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 # This file tests that FTS5 handles corrupt databases (i.e. internal
13 # inconsistencies in the backing tables) correctly. In this case
14 # "correctly" means without crashing.
15 #
16
17 source [file join [file dirname [info script]] fts5_common.tcl]
18 set testprefix fts5corrupt6
19
20 # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
21 ifcapable !fts5 {
22 finish_test
23 return
24 }
25 sqlite3_fts5_may_be_corrupt 1
26 database_may_be_corrupt
27
28 proc editblock {block} {
29 binary format Sa* 20000 [string range $block 2 end]
30 }
31 db func editblock editblock
32
33 do_execsql_test 1.0 {
34 CREATE VIRTUAL TABLE ft USING fts5(abc, def);
35 WITH a(i) AS (
36 SELECT 1 UNION ALL SELECT i+1 FROM a WHERE i<1000
37 )
38 INSERT INTO ft SELECT
39 'abc abc abc abc abc abc abc abc abc abc',
40 'def def def def def def def def def def'
41 FROM a;
42 UPDATE ft_data SET block = editblock(block) WHERE id=(
43 SELECT id FROM ft_data ORDER BY id LIMIT 1 OFFSET 5
44 );
45 }
46
47 do_catchsql_test 1.1 {
48 SELECT rowid FROM ft('def') ORDER BY rowid DESC LIMIT 1 OFFSET 9999;
49 } {1 {database disk image is malformed}}
50
51
52 sqlite3_fts5_may_be_corrupt 0
53 finish_test
54