3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
12 # This file contains tests for the content= and content_rowid= options.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5contentless
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
24 # Check that it is not possible to specify "contentless_delete=1" for
25 # anything other than a contentless table.
28 set res(1) {1 {contentless_delete=1 requires a contentless table}}
29 foreach {tn sql bError} {
30 1 "(a, b, contentless_delete=1)" 1
31 2 "(a, b, contentless_delete=1, content=abc)" 1
32 3 "(a, b, contentless_delete=1, content=)" 0
33 4 "(content=, contentless_delete=1, a)" 0
34 5 "(content='', contentless_delete=1, hello)" 0
37 do_catchsql_test 1.$tn "CREATE VIRTUAL TABLE t1 USING fts5 $sql" $res($bError)
41 # Check that it is not possible to specify "contentless_delete=1"
42 # along with columnsize=1.
45 set res(1) {1 {contentless_delete=1 is incompatible with columnsize=0}}
46 foreach {tn sql bError} {
47 2 "(a, b, content='', contentless_delete=1, columnsize=0)" 1
50 do_catchsql_test 1.$tn "CREATE VIRTUAL TABLE t1 USING fts5 $sql" $res($bError)
54 # Check that if contentless_delete=1 is specified, then the "origin"
55 # column is added to the %_docsize table.
58 CREATE VIRTUAL TABLE x1 USING fts5(c, content='');
59 CREATE VIRTUAL TABLE x2 USING fts5(c, content='', contentless_delete=1);
62 SELECT sql FROM sqlite_schema WHERE name IN ('x1_docsize', 'x2_docsize');
64 {CREATE TABLE 'x1_docsize'(id INTEGER PRIMARY KEY, sz BLOB)}
65 {CREATE TABLE 'x2_docsize'(id INTEGER PRIMARY KEY, sz BLOB, origin INTEGER)}
68 do_execsql_test 3.2.1 {
69 SELECT hex(block) FROM x1_data WHERE id=10
71 do_execsql_test 3.2.2 {
72 SELECT hex(block) FROM x2_data WHERE id=10
73 } {00000000FF000001000000}
76 INSERT INTO x2 VALUES('first text');
77 INSERT INTO x2 VALUES('second text');
80 SELECT id, origin FROM x2_docsize
83 SELECT level, segment, loc1, loc2 FROM fts5_structure(
84 (SELECT block FROM x2_data WHERE id=10)
91 INSERT INTO x2(x2) VALUES('optimize');
94 SELECT level, segment, loc1, loc2 FROM fts5_structure(
95 (SELECT block FROM x2_data WHERE id=10)
101 do_execsql_test 3.8 {
102 DELETE FROM x2 WHERE rowid=2;
105 do_execsql_test 3.9 {
106 SELECT rowid FROM x2('text')
109 #--------------------------------------------------------------------------
112 set vocab [list A B C D E F G H I J K L M N O P Q R S T U V W X Y Z]
114 for {set ii 0} {$ii < $n} {incr ii} {
115 lappend ret [lindex $vocab [expr int(rand()*[llength $vocab])]]
122 do_execsql_test 4.0 {
124 CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
125 INSERT INTO ft(ft, rank) VALUES('pgsz', 100);
128 for {set ii 0} {$ii < $nRow} {incr ii} {
131 INSERT INTO t1 VALUES($doc);
132 INSERT INTO ft VALUES($doc);
137 foreach v {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
138 set L1 [execsql {SELECT rowid FROM t1 WHERE x LIKE '%'||$v||'%'}]
139 set L2 [execsql {SELECT rowid FROM ft($v)}]
140 do_test 4.2.$v { set L1 } $L2
144 for {set ii 1} {$ii < $nRow} {incr ii 2} {
146 DELETE FROM ft WHERE rowid=$ii;
147 DELETE FROM t1 WHERE rowid=$ii;
152 foreach v {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
153 set L1 [execsql {SELECT rowid FROM t1 WHERE x LIKE '%'||$v||'%'}]
154 set L2 [execsql {SELECT rowid FROM ft($v)}]
155 do_test 4.4.$v { set L1 } $L2
158 do_execsql_test 4.5 {
159 INSERT INTO ft(ft) VALUES('optimize');
162 foreach v {A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} {
163 set L1 [execsql {SELECT rowid FROM t1 WHERE x LIKE '%'||$v||'%'}]
164 set L2 [execsql {SELECT rowid FROM ft($v)}]
165 do_test 4.6.$v { set L1 } $L2
168 #execsql_pp { SELECT fts5_decode(id, block) FROM ft_data }
170 #-------------------------------------------------------------------------
172 do_execsql_test 5.0 {
173 CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
174 INSERT INTO ft(rowid, x) VALUES(1, 'one two three');
175 INSERT INTO ft(rowid, x) VALUES(2, 'one two four');
176 INSERT INTO ft(rowid, x) VALUES(3, 'one two five');
177 INSERT INTO ft(rowid, x) VALUES(4, 'one two seven');
178 INSERT INTO ft(rowid, x) VALUES(5, 'one two eight');
181 do_execsql_test 5.1 {
182 DELETE FROM ft WHERE rowid=2
185 do_execsql_test 5.2 {
189 do_catchsql_test 5.3 {
190 UPDATE ft SET x='four six' WHERE rowid=3
193 do_execsql_test 5.4 {
194 SELECT rowid FROM ft('one');
197 do_execsql_test 5.5 {
198 REPLACE INTO ft(rowid, x) VALUES(3, 'four six');
199 SELECT rowid FROM ft('one');
202 do_execsql_test 5.6 {
203 REPLACE INTO ft(rowid, x) VALUES(6, 'one two eleven');
204 SELECT rowid FROM ft('one');
207 #-------------------------------------------------------------------------
209 do_execsql_test 6.0 {
210 CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
211 INSERT INTO ft(rowid, x) VALUES(1, 'one two three');
212 INSERT INTO ft(rowid, x) VALUES(2, 'one two four');
216 db eval { SELECT rowid FROM ft('one two') } {
218 db eval { INSERT INTO ft(rowid, x) VALUES(3, 'one two four') }
223 #-------------------------------------------------------------------------
225 do_execsql_test 7.0 {
226 CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
229 set lRowid [list -450 0 1 2 42]
234 execsql { INSERT INTO ft(rowid, x) VALUES($r, 'one one one'); }
242 execsql { REPLACE INTO ft(rowid, x) VALUES($r, 'two two two'); }
247 do_execsql_test 7.3 { SELECT rowid FROM ft('one'); } {}
248 do_execsql_test 7.4 { SELECT rowid FROM ft('two'); } $lRowid
250 #-------------------------------------------------------------------------
252 do_execsql_test 8.0 {
253 CREATE VIRTUAL TABLE ft USING fts5(x, content='', contentless_delete=1);
254 INSERT INTO ft VALUES('hello world');
255 INSERT INTO ft VALUES('one two three');
258 do_catchsql_test 8.1 {
259 INSERT INTO ft(ft, rowid, x) VALUES('delete', 1, 'hello world');
260 } {1 {'delete' may not be used with a contentless_delete=1 table}}
262 do_execsql_test 8.2 {
264 INSERT INTO ft(rowid, x) VALUES(3, 'four four four');
265 DELETE FROM ft WHERE rowid=3;
267 SELECT rowid FROM ft('four');