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/fts5secure4.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 / fts5secure4.test` 170 lines ยท 4736 bytes Raw Blame History 1 # 2023 April 14 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 return_if_no_fts5 15 set ::testprefix fts5secure4 16 17 #------------------------------------------------------------------------- 18 # Test using the 'delete' command to attempt to delete a token that 19 # is not present in the index in secure-delete mode. 20 # 21 do_execsql_test 1.0 { 22 CREATE VIRTUAL TABLE t1 USING fts5(a, b, content=x1); 23 24 CREATE TABLE x1(rowid INTEGER PRIMARY KEY, a, b); 25 INSERT INTO x1 VALUES 26 (1, 'hello world', 'today xyz'), 27 (2, 'not the day', 'crunch crumble and chomp'), 28 (3, 'one', 'two'); 29 INSERT INTO t1(t1) VALUES('rebuild'); 30 } 31 32 do_execsql_test 1.1 { 33 INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); 34 } 35 36 do_execsql_test 1.2 { 37 INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 4, 'nosuchtoken', ''); 38 } 39 40 do_execsql_test 1.3 { 41 INSERT INTO t1(t1) VALUES('integrity-check'); 42 } 43 44 do_execsql_test 1.4 { 45 INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 1, 'crunch', ''); 46 } 47 48 do_execsql_test 1.5 { 49 INSERT INTO t1(t1, rowid, a, b) VALUES('delete', 3, 'crunch', ''); 50 } 51 52 do_execsql_test 1.6 { 53 INSERT INTO t1(t1) VALUES('integrity-check'); 54 } 55 56 do_execsql_test 1.7 { 57 CREATE VIRTUAL TABLE y1 USING fts5(xx, prefix='1,2'); 58 INSERT INTO y1(y1, rank) VALUES('pgsz', 64); 59 INSERT INTO y1(y1, rank) VALUES('secure-delete', 1); 60 } 61 do_execsql_test 1.8 { 62 BEGIN; 63 INSERT INTO y1(rowid, xx) VALUES(1, 'abc def'); 64 INSERT INTO y1(rowid, xx) VALUES(2, 'reallyreallylongtoken'); 65 COMMIT; 66 } 67 do_execsql_test 1.9 { 68 DELETE FROM y1 WHERE rowid=1; 69 INSERT INTO y1(y1) VALUES('integrity-check'); 70 } 71 72 do_execsql_test 1.10 { 73 CREATE VIRTUAL TABLE w1 USING fts5(ww, content=""); 74 INSERT INTO w1(rowid, ww) VALUES(123, ''); 75 } 76 do_catchsql_test 1.11 { 77 INSERT INTO w1(w1, rowid, ww) VALUES('delete', 123, 'xyz'); 78 } {1 {database disk image is malformed}} 79 do_catchsql_test 1.12 { 80 DROP TABLE w1; 81 CREATE VIRTUAL TABLE w1 USING fts5(ww, content=""); 82 INSERT INTO w1(rowid, ww) VALUES(123, ''); 83 DELETE FROM w1_data WHERE id>10; 84 INSERT INTO w1(w1, rowid, ww) VALUES('delete', 123, 'xyz'); 85 } {1 {database disk image is malformed}} 86 87 #------------------------------------------------------------------------- 88 # Test using secure-delete with detail=none or detail=col. 89 # 90 foreach {tn d} {1 full 2 none 3 column} { 91 reset_db 92 do_execsql_test 2.$tn.1 " 93 CREATE VIRTUAL TABLE x1 USING fts5(xx, yy, zz, detail=$d, prefix='10,20'); 94 INSERT INTO x1(x1, rank) VALUES('pgsz', 64); 95 INSERT INTO x1(x1, rank) VALUES('secure-delete', 1); 96 " 97 98 do_execsql_test 2.$tn.2 { 99 BEGIN; 100 INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c'); 101 INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c'); 102 INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c'); 103 INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c'); 104 INSERT INTO x1(xx, yy, zz) VALUES('a b c', 'd e f', 'a b c'); 105 COMMIT; 106 INSERT INTO x1(x1) VALUES('integrity-check'); 107 } 108 109 do_execsql_test 2.$tn.3 { 110 DELETE FROM x1 WHERE rowid IN (2, 4, 6); 111 INSERT INTO x1(x1) VALUES('integrity-check'); 112 } 113 114 do_execsql_test 2.$tn.4 { 115 DELETE FROM x1 WHERE rowid IN (1, 3, 5); 116 INSERT INTO x1(x1) VALUES('integrity-check'); 117 } 118 119 do_execsql_test 2.$tn.5 { 120 WITH s(i) AS ( 121 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<100 122 ) 123 INSERT INTO x1 124 SELECT 'seems to be', 'used brew to', 'everything is working' FROM s 125 UNION ALL 126 SELECT 'used brew to', 'everything is working', 'seems to be' FROM s 127 UNION ALL 128 SELECT 'everything is working', 'seems to be', 'used brew to' FROM s 129 UNION ALL 130 SELECT 'abc', 'zzz', 'a b c d' 131 UNION ALL 132 SELECT 'z', 'z', 'z' FROM s 133 } 134 135 do_test 2.$tn.6 { 136 for {set i 300} {$i > 200} {incr i -1} { 137 execsql { 138 DELETE FROM x1 WHERE rowid=$i; 139 INSERT INTO x1(x1) VALUES('integrity-check'); 140 } 141 } 142 } {} 143 144 do_test 2.$tn.7 { 145 for {set i 1} {$i < 100} {incr i} { 146 execsql { 147 DELETE FROM x1 WHERE rowid=$i; 148 INSERT INTO x1(x1) VALUES('integrity-check'); 149 } 150 } 151 } {} 152 153 do_test 2.$tn.8 { 154 foreach i [db eval {SELECT rowid FROM x1}] { 155 execsql { 156 DELETE FROM x1 WHERE rowid=$i; 157 INSERT INTO x1(x1) VALUES('integrity-check'); 158 } 159 } 160 } {} 161 162 do_execsql_test 2.$tn.9 { 163 SELECT * FROM x1 164 } {} 165 } 166 167 168 169 finish_test 170