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 / fts5secure3.test
| 1 | # 2023 Feb 17 |
| 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 | # TESTRUNNER: slow |
| 13 | # |
| 14 | |
| 15 | source [file join [file dirname [info script]] fts5_common.tcl] |
| 16 | ifcapable !fts5 { finish_test ; return } |
| 17 | set ::testprefix fts5secure3 |
| 18 | |
| 19 | do_execsql_test 1.0 { |
| 20 | CREATE VIRTUAL TABLE ft USING fts5(col); |
| 21 | INSERT INTO ft VALUES('data for the table'); |
| 22 | INSERT INTO ft VALUES('more of the same'); |
| 23 | INSERT INTO ft VALUES('and extra data'); |
| 24 | |
| 25 | INSERT INTO ft(ft, rank) VALUES('secure-delete', 1); |
| 26 | } |
| 27 | |
| 28 | do_execsql_test 1.1 { |
| 29 | BEGIN; |
| 30 | INSERT INTO ft(rowid, col) VALUES(0, 'the next data'); |
| 31 | DELETE FROM ft WHERE rowid=1; |
| 32 | DELETE FROM ft WHERE rowid=2; |
| 33 | INSERT INTO ft(rowid, col) VALUES(6, 'with some more of the same data'); |
| 34 | COMMIT; |
| 35 | } |
| 36 | |
| 37 | do_execsql_test 1.2 { |
| 38 | INSERT INTO ft(ft) VALUES('integrity-check'); |
| 39 | } |
| 40 | |
| 41 | #------------------------------------------------------------------------- |
| 42 | |
| 43 | reset_db |
| 44 | do_execsql_test 2.0 { |
| 45 | CREATE VIRTUAL TABLE t1 USING fts5(x); |
| 46 | INSERT INTO t1(t1, rank) VALUES('pgsz', 64); |
| 47 | INSERT INTO t1(t1, rank) VALUES('secure-delete', 1); |
| 48 | BEGIN; |
| 49 | INSERT INTO t1 VALUES('the start'); |
| 50 | } |
| 51 | do_test 2.1 { |
| 52 | for {set i 0} {$i < 1000} {incr i} { |
| 53 | execsql { INSERT INTO t1 VALUES('the ' || hex(randomblob(3))) } |
| 54 | } |
| 55 | execsql { |
| 56 | INSERT INTO t1 VALUES('the end'); |
| 57 | COMMIT; |
| 58 | } |
| 59 | } {} |
| 60 | |
| 61 | do_execsql_test 2.2 { |
| 62 | DELETE FROM t1 WHERE rowid BETWEEN 2 AND 1000; |
| 63 | } |
| 64 | |
| 65 | do_execsql_test 2.3 { |
| 66 | INSERT INTO t1(t1) VALUES('integrity-check'); |
| 67 | } |
| 68 | |
| 69 | do_execsql_test 2.6 { |
| 70 | INSERT INTO t1(rowid, x) VALUES(500, 'middle'); |
| 71 | INSERT INTO t1(rowid, x) VALUES(501, 'value'); |
| 72 | SELECT * FROM t1('the middle'); |
| 73 | } |
| 74 | |
| 75 | do_execsql_test 2.7 { |
| 76 | INSERT INTO t1(t1) VALUES('optimize'); |
| 77 | } |
| 78 | |
| 79 | do_execsql_test 2.8 { |
| 80 | SELECT count(*) FROM t1_data |
| 81 | } 4 |
| 82 | |
| 83 | #execsql_pp { SELECT id, quote(block), fts5_decode(id, block) FROM t1_data; } |
| 84 | |
| 85 | #------------------------------------------------------------------------- |
| 86 | # Tests with large/small rowid values. |
| 87 | # |
| 88 | |
| 89 | foreach {tn cfg} { |
| 90 | 1 "" |
| 91 | 2 "INSERT INTO fff(fff, rank) VALUES('secure-delete', 1)" |
| 92 | } { |
| 93 | reset_db |
| 94 | |
| 95 | expr srand(0) |
| 96 | |
| 97 | set vocab { |
| 98 | Popper Poppins Popsicle Porfirio Porrima Porsche |
| 99 | Porter Portia Portland Portsmouth Portugal Portuguese |
| 100 | Poseidon Post PostgreSQL Potemkin Potomac Potsdam |
| 101 | Pottawatomie Potter Potts Pound Poussin Powell |
| 102 | PowerPC PowerPoint Powers Powhatan Poznan Prada |
| 103 | Prado Praetorian Prague Praia Prakrit Pratchett |
| 104 | Pratt Pravda Praxiteles Preakness Precambrian Preminger |
| 105 | Premyslid Prensa Prentice Pres Presbyterian Presbyterianism |
| 106 | } |
| 107 | proc newdoc {} { |
| 108 | for {set i 0} {$i<8} {incr i} { |
| 109 | lappend ret [lindex $::vocab [expr int(abs(rand()) * [llength $::vocab])]] |
| 110 | } |
| 111 | set ret |
| 112 | } |
| 113 | db func newdoc newdoc |
| 114 | |
| 115 | do_execsql_test 3.$tn.0 { |
| 116 | CREATE VIRTUAL TABLE fff USING fts5(y); |
| 117 | INSERT INTO fff(fff, rank) VALUES('pgsz', 64); |
| 118 | |
| 119 | WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 ) |
| 120 | INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s; |
| 121 | |
| 122 | WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 ) |
| 123 | INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s; |
| 124 | |
| 125 | WITH s(x) AS ( VALUES(1) UNION ALL SELECT x+1 FROM s WHERE x<1000 ) |
| 126 | INSERT INTO fff(rowid, y) SELECT random() , newdoc() FROM s; |
| 127 | } |
| 128 | |
| 129 | execsql $cfg |
| 130 | |
| 131 | proc lshuffle {in} { |
| 132 | set out [list] |
| 133 | while {[llength $in]>0} { |
| 134 | set idx [expr int(abs(rand()) * [llength $in])] |
| 135 | lappend out [lindex $in $idx] |
| 136 | set in [lreplace $in $idx $idx] |
| 137 | } |
| 138 | set out |
| 139 | } |
| 140 | |
| 141 | #dump fff |
| 142 | |
| 143 | set iTest 1 |
| 144 | foreach ii [lshuffle [db eval {SELECT rowid FROM fff}]] { |
| 145 | #if {$iTest==1} { dump fff } |
| 146 | #if {$iTest==1} { breakpoint } |
| 147 | do_execsql_test 3.$tn.1.$iTest.$ii { |
| 148 | DELETE FROM fff WHERE rowid=$ii; |
| 149 | } |
| 150 | #if {$iTest==1} { dump fff } |
| 151 | if {($iTest % 20)==0} { |
| 152 | do_execsql_test 3.$tn.1.$iTest.$ii.ic { |
| 153 | INSERT INTO fff(fff) VALUES('integrity-check'); |
| 154 | } |
| 155 | } |
| 156 | #if {$iTest==1} { break } |
| 157 | incr iTest |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | #execsql_pp { SELECT rowid FROM fff('post') ORDER BY rowid ASC } |
| 162 | #breakpoint |
| 163 | #execsql_pp { |
| 164 | # SELECT rowid FROM fff('post') ORDER BY rowid DESC |
| 165 | #} |
| 166 | # |
| 167 | #dump fff |
| 168 | |
| 169 | |
| 170 | finish_test |
| 171 |