Snapshot of upstream SQLite 3.40.1
[sqlcipher.git] / ext / fts5 / test / fts5corrupt6.test
blob6403d3a406374d981361f919f563d1b0fcf23671
1 # 2015 Apr 24
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 FTS5 handles corrupt databases (i.e. internal
13 # inconsistencies in the backing tables) correctly. In this case 
14 # "correctly" means without crashing.
17 source [file join [file dirname [info script]] fts5_common.tcl]
18 set testprefix fts5corrupt6
20 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
21 ifcapable !fts5 {
22   finish_test
23   return
25 sqlite3_fts5_may_be_corrupt 1
26 database_may_be_corrupt
28 proc editblock {block} {
29   binary format Sa* 20000 [string range $block 2 end]
31 db func editblock editblock
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   );
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}}
52 sqlite3_fts5_may_be_corrupt 0
53 finish_test