sqlite
[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.
Brought by drakestapleton
sqlite / ext / fts5 / test / fts5version.test
| 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 | # The tests in this file focus on testing that unrecognized file-format |
| 13 | # versions are detected and reported. |
| 14 | # |
| 15 | |
| 16 | source [file join [file dirname [info script]] fts5_common.tcl] |
| 17 | set testprefix fts5version |
| 18 | |
| 19 | # If SQLITE_ENABLE_FTS5 is not defined, omit this file. |
| 20 | ifcapable !fts5 { |
| 21 | finish_test |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | |
| 26 | do_execsql_test 1.1 { |
| 27 | CREATE VIRTUAL TABLE t1 USING fts5(one); |
| 28 | INSERT INTO t1 VALUES('a b c d'); |
| 29 | } {} |
| 30 | |
| 31 | do_execsql_test 1.2 { |
| 32 | SELECT * FROM t1_config WHERE k='version' |
| 33 | } {version 4} |
| 34 | |
| 35 | do_execsql_test 1.3 { |
| 36 | SELECT rowid FROM t1 WHERE t1 MATCH 'a'; |
| 37 | } {1} |
| 38 | |
| 39 | sqlite3_db_config db DEFENSIVE 0 |
| 40 | do_execsql_test 1.4 { |
| 41 | UPDATE t1_config set v=6 WHERE k='version'; |
| 42 | } |
| 43 | |
| 44 | do_test 1.5 { |
| 45 | db close |
| 46 | sqlite3 db test.db |
| 47 | catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' } |
| 48 | } {1 {invalid fts5 file format (found 6, expected 4 or 5) - run 'rebuild'}} |
| 49 | |
| 50 | do_test 1.6 { |
| 51 | db close |
| 52 | sqlite3 db test.db |
| 53 | catchsql { INSERT INTO t1 VALUES('x y z') } |
| 54 | } {1 {invalid fts5 file format (found 6, expected 4 or 5) - run 'rebuild'}} |
| 55 | |
| 56 | do_test 1.7 { |
| 57 | sqlite3_db_config db DEFENSIVE 0 |
| 58 | execsql { DELETE FROM t1_config WHERE k='version' } |
| 59 | db close |
| 60 | sqlite3 db test.db |
| 61 | catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' } |
| 62 | } {1 {invalid fts5 file format (found 0, expected 4 or 5) - run 'rebuild'}} |
| 63 | |
| 64 | do_test 1.8 { |
| 65 | sqlite3_db_config db DEFENSIVE 0 |
| 66 | execsql { INSERT INTO t1_config VALUES('version', 4) } |
| 67 | execsql { INSERT INTO t1(t1, rank) VALUES('secure-delete', 1) } |
| 68 | } {} |
| 69 | |
| 70 | do_execsql_test 1.10 { |
| 71 | SELECT * FROM t1_config |
| 72 | } {secure-delete 1 version 4} |
| 73 | |
| 74 | do_execsql_test 1.11 { |
| 75 | INSERT INTO t1(rowid, one) VALUES(123, 'one two three'); |
| 76 | DELETE FROM t1 WHERE rowid=123; |
| 77 | SELECT * FROM t1_config |
| 78 | } {secure-delete 1 version 5} |
| 79 | |
| 80 | do_execsql_test 1.11 { |
| 81 | INSERT INTO t1(t1) VALUES('rebuild'); |
| 82 | SELECT * FROM t1_config |
| 83 | } {secure-delete 1 version 4} |
| 84 | |
| 85 | do_execsql_test 1.12 { |
| 86 | SELECT * FROM t1_config |
| 87 | } {secure-delete 1 version 4} |
| 88 | |
| 89 | #------------------------------------------------------------------------- |
| 90 | reset_db |
| 91 | |
| 92 | do_execsql_test 2.0 { |
| 93 | CREATE VIRTUAL TABLE xyz USING fts5(x); |
| 94 | INSERT INTO xyz(rowid, x) VALUES |
| 95 | (1, 'one document'), |
| 96 | (2, 'two document'), |
| 97 | (3, 'three document'), |
| 98 | (4, 'four document'), |
| 99 | (5, 'five document'), |
| 100 | (6, 'six document'); |
| 101 | |
| 102 | INSERT INTO xyz(xyz, rank) VALUES('secure-delete', 1); |
| 103 | SELECT v FROM xyz_config WHERE k='version'; |
| 104 | } {4} |
| 105 | |
| 106 | do_execsql_test 2.1 { |
| 107 | BEGIN; |
| 108 | INSERT INTO xyz(rowid, x) VALUES(7, 'seven document'); |
| 109 | SAVEPOINT one; |
| 110 | DELETE FROM xyz WHERE rowid = 4; |
| 111 | } |
| 112 | |
| 113 | do_execsql_test 2.2 { |
| 114 | SELECT v FROM xyz_config WHERE k='version'; |
| 115 | } {4} |
| 116 | |
| 117 | do_execsql_test 2.3 { |
| 118 | ROLLBACK TO one; |
| 119 | SELECT v FROM xyz_config WHERE k='version'; |
| 120 | } {4} |
| 121 | |
| 122 | |
| 123 | do_execsql_test 2.4 { |
| 124 | DELETE FROM xyz WHERE rowid = 3; |
| 125 | COMMIT; |
| 126 | SELECT v FROM xyz_config WHERE k='version'; |
| 127 | } {5} |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | finish_test |
| 133 |