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 #*************************************************************************
11 # This file implements regression tests for SQLite library. The
12 # focus of this script is testing the FTS5 module.
15 source [file join [file dirname [info script]] fts5_common.tcl]
16 set testprefix fts5update
18 # If SQLITE_ENABLE_FTS5 is not defined, omit this file.
25 "eight zero iv eight 7" "ix one 8 one three ii one"
26 "1 9 9 three viii" "5 zero ii 6 nine ix 3"
27 "3 zero 5 2 seven nine" "two eight viii eight 1"
28 "4 six two 5 9 vii" "viii ii four 8 i i iv"
29 "vii 0 iv seven 7 viii" "five 1 nine vi seven"
30 "1 zero zero iii 1" "one one six 6 nine seven"
31 "one v 4 zero 4 iii ii" "2 3 eight six ix"
32 "six iv 7 three 5" "ix zero 0 8 ii 7 3"
33 "four six nine 2 vii 3" "five viii 5 8 0 7"
36 foreach_detail_mode $::testprefix {
39 CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=%DETAIL%);
44 execsql {INSERT INTO t1 VALUES($a, $b)}
48 proc update {iRowid iA iB} {
49 set a [lindex $::docs $iA]
50 set b [lindex $::docs $iB]
51 execsql { UPDATE t1 SET a=$a, b=$b WHERE rowid=$iRowid }
54 set nDoc [llength $::docs]
55 foreach n {1 5 10 50 100} {
58 for {set i 1} {$i <= 1000} {incr i} {
59 set iRowid [expr {int(rand() * ($nDoc/2)) + 1}]
60 set iA [expr {int(rand() * $nDoc)}]
61 set iB [expr {int(rand() * $nDoc)}]
62 update $iRowid $iA $iB
65 execsql { COMMIT; BEGIN }
69 execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
73 execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
78 UPDATE t1 SET a=a AND b=b;
79 INSERT INTO t1(t1) VALUES('integrity-check');
83 execsql { INSERT INTO t1(t1, rank) VALUES('pgsz', 32) }
84 for {set i 0} {$i < 50} {incr i} {
85 execsql { UPDATE t1 SET a=a AND b=b }
86 execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
90 #-------------------------------------------------------------------------
91 # Lots of deletes/inserts of the same document with the same rowid.
94 CREATE VIRTUAL TABLE x2 USING fts5(x, detail=%DETAIL%);
95 INSERT INTO x2(x2, rank) VALUES('crisismerge', 2);
96 INSERT INTO x2 VALUES('a b c');
97 INSERT INTO x2 VALUES('a b c');
100 for {set i 0} {$i < 1000} {incr i} {
101 execsql { DELETE FROM x2 WHERE rowid = 2 }
102 execsql { INSERT INTO x2(rowid, x) VALUES(2, 'a b c') }
105 do_execsql_test 2.1.integrity {
106 INSERT INTO x2(x2) VALUES('integrity-check');
110 for {set i 0} {$i < 1000} {incr i} {
111 execsql { UPDATE x2 SET x=x WHERE rowid=2 }
114 do_execsql_test 2.2.integrity {
115 INSERT INTO x2(x2) VALUES('integrity-check');
118 #-------------------------------------------------------------------------
120 do_execsql_test 3.0 {
121 CREATE VIRTUAL TABLE x3 USING fts5(x, detail=%DETAIL%);
122 INSERT INTO x3 VALUES('one');
123 INSERT INTO x3 VALUES('two');
124 INSERT INTO x3 VALUES('one');
125 INSERT INTO x3 VALUES('two');
126 INSERT INTO x3 VALUES('one');
130 db eval { SELECT * FROM x3('one') } {
132 INSERT INTO x3(x3) VALUES('optimize');
137 do_execsql_test 4.0 {
138 CREATE VIRTUAL TABLE x4 USING fts5(a, detail=%DETAIL%);
139 INSERT INTO x4 VALUES('one two three');
140 INSERT INTO x4(rowid, a) VALUES('2', 'one two three');
141 INSERT INTO x4(rowid, a) VALUES('3.0', 'one two three');
143 do_catchsql_test 4.1 {
144 INSERT INTO x4(rowid, a) VALUES('four', 'one two three');
145 } {1 {datatype mismatch}}
147 do_catchsql_test 4.2 {
148 UPDATE x4 SET rowid = 'four' WHERE rowid=1;
149 } {1 {datatype mismatch}}
155 do_catchsql_test 4.0 { CREATE VIRTUAL TABLE t1 USING fts5(a,b,c); } {0 {}}
156 do_catchsql_test 4.1 { DELETE FROM t1 WHERE t1 MATCH 'f*'; } {0 {}}