Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/sqlite/blob/master/ext/fts5/test/fts5corrupt8.test # sqlite [Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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 13 source [file join [file dirname [info script]] fts5_common.tcl] 14 set testprefix fts5corrupt8 15 16 # If SQLITE_ENABLE_FTS5 is not defined, omit this file. 17 ifcapable !fts5 { 18 finish_test 19 return 20 } 21 22 do_execsql_test 1.0 { 23 CREATE VIRTUAL TABLE t1 USING fts5(x); 24 } 25 26 do_execsql_test 1.1 { 27 UPDATE t1_data SET block='hello world' WHERE id=10 28 } 29 30 db close 31 sqlite3 db test.db 32 33 do_catchsql_test 1.2 { 34 SELECT * FROM t1 35 } {1 {fts5: corrupt structure record for table "t1"}} 36 do_catchsql_test 1.3 { 37 DROP TABLE t1 38 } {0 {}} 39 do_execsql_test 1.4 { 40 SELECT * FROM sqlite_schema 41 } 42 43 do_execsql_test 2.0 { 44 CREATE VIRTUAL TABLE t1 USING fts5(x); 45 } 46 do_execsql_test 2.1 { 47 UPDATE t1_config SET v=555 WHERE k='version' 48 } 49 db close 50 sqlite3 db test.db 51 do_catchsql_test 2.2 { 52 SELECT * FROM t1 53 } {1 {invalid fts5 file format (found 555, expected 4 or 5) - run 'rebuild'}} 54 do_catchsql_test 2.3 { 55 DROP TABLE t1 56 } {1 {invalid fts5 file format (found 555, expected 4 or 5) - run 'rebuild'}} 57 do_test 2.4 { 58 sqlite3_fts5_drop_corrupt_table db main t1 59 } {} 60 do_execsql_test 2.5 { 61 SELECT * FROM sqlite_schema 62 } 63 64 do_execsql_test 3.0 { 65 CREATE VIRTUAL TABLE t1 USING fts5(x); 66 } 67 do_execsql_test 3.1 { 68 DELETE FROM t1_config; 69 } 70 db close 71 sqlite3 db test.db 72 do_catchsql_test 3.2 { 73 SELECT * FROM t1 74 } {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}} 75 do_catchsql_test 3.3 { 76 DROP TABLE t1 77 } {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}} 78 79 80 do_test 3.4 { 81 sqlite3_db_config db DEFENSIVE 1 82 } {1} 83 do_test 3.5 { 84 sqlite3_fts5_drop_corrupt_table db main t1 85 } {} 86 do_test 3.6 { 87 sqlite3_db_config db DEFENSIVE -1 88 } {1} 89 do_execsql_test 3.7 { 90 SELECT * FROM sqlite_schema 91 } 92 93 #------------------------------------------------------------------------- 94 reset_db 95 96 proc hex_to_blob {hex} { 97 binary encode hex $hex 98 } 99 db func hex_to_blob hex_to_blob 100 101 do_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 110 do_execsql_test 4.1 { 111 SELECT hex(block) FROM x1_data WHERE id=10 112 } { 113 00000000FF00000101010200010101010101010102 114 } 115 116 do_execsql_test 4.2.1 { 117 UPDATE x1_data SET block= 118 X'00000000FF00000101010200010101010101819C9B95A8000102' 119 WHERE id=10; 120 } 121 122 do_catchsql_test 4.2.2 { 123 SELECT * FROM x1('c d e'); 124 } {1 {out of memory}} 125 126 do_execsql_test 4.3.1 { 127 UPDATE x1_data SET block= 128 X'00000000FF000001010102000101010101019282AFF9A0000102' 129 WHERE id=10; 130 } 131 132 do_catchsql_test 4.3.2 { 133 SELECT * FROM x1('c d e'); 134 } {1 {out of memory}} 135 136 do_execsql_test 4.4.1 { 137 UPDATE x1_data SET block= 138 X'00000000FF000001010102000101010101018181808080130102' 139 WHERE id=10; 140 } 141 142 do_catchsql_test 4.3.2 { 143 SELECT * FROM x1('c d e'); 144 } {1 {out of memory}} 145 146 finish_test 147