interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / fts5 / test / fts5secure6.test

141 lines · 3259 bytes Raw Blame History
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
13source [file join [file dirname [info script]] fts5_common.tcl]
14ifcapable !fts5 { finish_test ; return }
15set ::testprefix fts5secure6
16
17db progress 1 progress_handler
18set ::PHC 0
19proc progress_handler {args} {
20 incr ::PHC
21 # if {($::PHC % 100000)==0} breakpoint
22 return 0
23}
24
25proc setup {} {
26 db eval {
27 DROP TABLE IF EXISTS t1;
28 CREATE VIRTUAL TABLE t1 USING fts5(x);
29 WITH s(i) AS (
30 VALUES(1) UNION ALL SELECT i+1 FROM s WHERE i<1000
31 )
32 INSERT INTO t1 SELECT 'a b c d e f g h i j k' FROM s;
33 }
34}
35
36foreach {tn sd} {
37 1 0
38 2 1
39} {
40 setup
41 do_execsql_test 1.$tn.0 {
42 INSERT INTO t1(t1, rank) VALUES('secure-delete', $sd)
43 }
44 set PHC 0
45 do_execsql_test 1.$tn.1 { DELETE FROM t1; }
46 set phc($tn) $PHC
47}
48
49do_test 1.3 {
50 expr $phc(1)*5 < $phc(2)
51} {1}
52
53#-------------------------------------------------------------------------
54reset_db
55
56do_execsql_test 2.0 {
57 CREATE VIRTUAL TABLE t1 USING fts5(x);
58 INSERT INTO t1(t1, rank) VALUES('secure-delete', $sd)
59}
60
61do_execsql_test 2.1 {
62 BEGIN;
63 INSERT INTO t1(rowid, x) VALUES(-100000, 'abc def ghi');
64 INSERT INTO t1(rowid, x) VALUES(-99999, 'abc def ghi');
65 INSERT INTO t1(rowid, x) VALUES(9223372036854775800, 'abc def ghi');
66 COMMIT;
67}
68
69do_execsql_test 2.2 {
70 SELECT rowid FROM t1('def')
71} {-100000 -99999 9223372036854775800}
72
73#-------------------------------------------------------------------------
74reset_db
75
76do_execsql_test 3.0 {
77 CREATE VIRTUAL TABLE t1 USING fts5(x);
78 INSERT INTO t1(t1, rank) VALUES('secure-delete', $sd)
79}
80
81do_execsql_test 3.1 {
82 BEGIN;
83 INSERT INTO t1(rowid, x)
84 VALUES(51869, 'when whenever where weress what turn'),
85 (51871, 'to were');
86 COMMIT;
87}
88
89do_execsql_test 3.2 {
90 DELETE FROM t1 WHERE rowid=51871;
91 INSERT INTO t1(t1) VALUES('integrity-check');
92}
93
94#-------------------------------------------------------------------------
95reset_db
96
97do_execsql_test 4.0 {
98 CREATE VIRTUAL TABLE t1 USING fts5(x);
99 INSERT INTO t1(rowid, x) VALUES(10, 'one two');
100}
101do_execsql_test 4.1 {
102 UPDATE t1 SET x = 'one three' WHERE rowid=10;
103 INSERT INTO t1(t1, rank) VALUES('secure-delete', 1);
104}
105do_execsql_test 4.2 {
106 DELETE FROM t1 WHERE rowid=10;
107}
108do_execsql_test 4.3 {
109 INSERT INTO t1(t1) VALUES('integrity-check');
110}
111
112#-------------------------------------------------------------------------
113reset_db
114
115do_execsql_test 5.0 {
116 CREATE VIRTUAL TABLE t1 USING fts5(content);
117
118 INSERT INTO t1(t1,rank) VALUES('secure-delete',1);
119 INSERT INTO t1 VALUES('active'),('boomer'),('atom'),('atomic'),
120 ('alpha channel backup abandon test aback boomer atom alpha active');
121 DELETE FROM t1 WHERE t1 MATCH 'abandon';
122}
123
124do_execsql_test 5.1 {
125 INSERT INTO t1(t1) VALUES('rebuild');
126}
127
128do_execsql_test 5.2 {
129 DELETE FROM t1 WHERE rowid NOTNULL<5;
130}
131
132db close
133sqlite3 db test.db
134
135do_execsql_test 5.3 {
136 PRAGMA integrity_check;
137} {ok}
138
139
140finish_test
141