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 fts5contentless2
18 # If SQLITE_ENABLE_FTS5 is defined, omit this file.
25 list aaa bbb ccc ddd eee fff ggg hhh iii jjj kkk lll mmm nnn ooo ppp
28 proc document {nToken} {
31 for {set ii 0} {$ii < $nToken} {incr ii} {
32 lappend doc [lindex $vocab [expr int(rand()*[llength $vocab])]]
36 db func document document
38 proc contains {doc token} {
39 expr {[lsearch $doc $token]>=0}
41 db func contains contains
43 proc do_compare_tables_test {tn} {
44 uplevel [list do_test $tn {
46 set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $v) }]
47 set l2 [execsql { SELECT rowid FROM t2($v) }]
48 if {$l1!=$l2} { error "1: query mismatch ($l1) ($l2)" }
50 set w "[string range $v 0 1]*"
51 set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $w) }]
52 set l2 [execsql { SELECT rowid FROM t2($w) }]
53 if {$l1!=$l2} { error "2: query mismatch ($l1) ($l2)" }
55 set w "[string range $v 0 0]*"
56 set l1 [execsql { SELECT rowid FROM t1 WHERE contains(doc, $w) }]
57 set l2 [execsql { SELECT rowid FROM t2($w) }]
58 if {$l1!=$l2} { error "2: query mismatch ($l1) ($l2)" }
61 SELECT rowid FROM t1 WHERE contains(doc, $v) ORDER BY rowid DESC
63 set l2 [execsql { SELECT rowid FROM t2($v) ORDER BY rowid DESC }]
64 if {$l1!=$l2} { error "1: query mismatch ($l1) ($l2)" }
73 foreach elem $in { lappend L [list [expr rand()] $elem] }
74 foreach pair [lsort -index 0 $L] { lappend ret [lindex $pair 1] }
81 CREATE VIRTUAL TABLE t2 USING fts5(
82 doc, prefix=2, content=, contentless_delete=1
86 CREATE TRIGGER tr1 AFTER DELETE ON t1 BEGIN
87 DELETE FROM t2 WHERE rowid = old.rowid;
91 set SMALLEST64 -9223372036854775808
92 set LARGEST64 9223372036854775807
96 2 $SMALLEST64 $SMALLEST64+50
97 3 $LARGEST64-50 $LARGEST64
105 for {set ii $r1} {$ii <= $r2} {incr ii} {
106 execsql { INSERT INTO t1(rowid, doc) VALUES ($ii, document(8)); }
112 db eval { SELECT rowid, doc FROM t1 } {
113 execsql { INSERT INTO t2(rowid, doc) VALUES($rowid, $doc) }
125 set rowid [expr $rowid]
126 do_execsql_test 1.3.$tn.1 {
127 DELETE FROM t1 WHERE rowid=$rowid
129 do_compare_tables_test 1.3.$tn.2
133 foreach r [lshuffle [execsql {SELECT rowid FROM t1}]] {
134 if {($iTest % 50)==0} {
135 execsql { INSERT INTO t2(t2) VALUES('optimize') }
137 if {($iTest % 5)==0} {
138 execsql { INSERT INTO t2(t2, rank) VALUES('merge', 5) }
140 do_execsql_test 1.4.$iTest.1($r) {
141 DELETE FROM t1 WHERE rowid=$r
143 do_compare_tables_test 1.4.$iTest.2
147 do_execsql_test 1.5 {
151 #-------------------------------------------------------------------------
153 db func document document
155 do_execsql_test 2.0 {
156 CREATE VIRTUAL TABLE t2 USING fts5(doc, content=, contentless_delete=1);
158 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
160 INSERT INTO t2(rowid, doc) SELECT i, i || ' ' || i FROM s;
163 do_execsql_test 2.1 {
165 DELETE FROM t2 WHERE rowid=32;
166 DELETE FROM t2 WHERE rowid=64;
167 DELETE FROM t2 WHERE rowid=96;
168 DELETE FROM t2 WHERE rowid=128;
169 DELETE FROM t2 WHERE rowid=160;
170 DELETE FROM t2 WHERE rowid=192;
174 do_execsql_test 2.2 {
175 SELECT * FROM t2('128');
178 #-------------------------------------------------------------------------
185 set step [expr $step]
188 db func document document
189 do_execsql_test 3.$tn.0 {
190 CREATE VIRTUAL TABLE t2 USING fts5(doc, content=, contentless_delete=1);
191 INSERT INTO t2(t2, rank) VALUES('pgsz', 100);
193 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<1000
195 INSERT INTO t2(rowid, doc) SELECT i, i || ' ' || i FROM s;
197 do_execsql_test 3.$tn.1 {
198 DELETE FROM t2 WHERE (rowid % $step)==0
200 do_execsql_test 3.$tn.2 {
201 SELECT * FROM t2( $step * 5 )