1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# 2016 Jan 16
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#*************************************************************************
# This file implements regression tests for SQLite library. The
# focus of this script is testing the FTS5 module.
#
source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5update
# If SQLITE_ENABLE_FTS5 is not defined, omit this file.
ifcapable !fts5 {
finish_test
return
}
set docs {
"eight zero iv eight 7" "ix one 8 one three ii one"
"1 9 9 three viii" "5 zero ii 6 nine ix 3"
"3 zero 5 2 seven nine" "two eight viii eight 1"
"4 six two 5 9 vii" "viii ii four 8 i i iv"
"vii 0 iv seven 7 viii" "five 1 nine vi seven"
"1 zero zero iii 1" "one one six 6 nine seven"
"one v 4 zero 4 iii ii" "2 3 eight six ix"
"six iv 7 three 5" "ix zero 0 8 ii 7 3"
"four six nine 2 vii 3" "five viii 5 8 0 7"
}
foreach_detail_mode $::testprefix {
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE t1 USING fts5(a, b, detail=%DETAIL%);
} {}
do_test 1.1 {
foreach {a b} $docs {
execsql {INSERT INTO t1 VALUES($a, $b)}
}
} {}
proc update {iRowid iA iB} {
set a [lindex $::docs $iA]
set b [lindex $::docs $iB]
execsql { UPDATE t1 SET a=$a, b=$b WHERE rowid=$iRowid }
}
set nDoc [llength $::docs]
foreach n {1 5 10 50 100} {
do_test 1.2.$n {
execsql BEGIN
for {set i 1} {$i <= 1000} {incr i} {
set iRowid [expr {int(rand() * ($nDoc/2)) + 1}]
set iA [expr {int(rand() * $nDoc)}]
set iB [expr {int(rand() * $nDoc)}]
update $iRowid $iA $iB
if {($i % $n)==0} {
execsql { COMMIT; BEGIN }
}
if {($i % $n)==100} {
execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
}
}
execsql COMMIT
execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
} {}
}
do_execsql_test 1.3 {
UPDATE t1 SET a=a AND b=b;
INSERT INTO t1(t1) VALUES('integrity-check');
}
do_test 1.4 {
execsql { INSERT INTO t1(t1, rank) VALUES('pgsz', 32) }
for {set i 0} {$i < 50} {incr i} {
execsql { UPDATE t1 SET a=a AND b=b }
execsql { INSERT INTO t1(t1) VALUES('integrity-check') }
}
} {}
#-------------------------------------------------------------------------
# Lots of deletes/inserts of the same document with the same rowid.
#
do_execsql_test 2.0 {
CREATE VIRTUAL TABLE x2 USING fts5(x, detail=%DETAIL%);
INSERT INTO x2(x2, rank) VALUES('crisismerge', 2);
INSERT INTO x2 VALUES('a b c');
INSERT INTO x2 VALUES('a b c');
}
do_test 2.1 {
for {set i 0} {$i < 1000} {incr i} {
execsql { DELETE FROM x2 WHERE rowid = 2 }
execsql { INSERT INTO x2(rowid, x) VALUES(2, 'a b c') }
}
} {}
do_execsql_test 2.1.integrity {
INSERT INTO x2(x2) VALUES('integrity-check');
}
do_test 2.2 {
for {set i 0} {$i < 1000} {incr i} {
execsql { UPDATE x2 SET x=x WHERE rowid=2 }
}
} {}
do_execsql_test 2.2.integrity {
INSERT INTO x2(x2) VALUES('integrity-check');
}
#-------------------------------------------------------------------------
#
do_execsql_test 3.0 {
CREATE VIRTUAL TABLE x3 USING fts5(x, detail=%DETAIL%);
INSERT INTO x3 VALUES('one');
INSERT INTO x3 VALUES('two');
INSERT INTO x3 VALUES('one');
INSERT INTO x3 VALUES('two');
INSERT INTO x3 VALUES('one');
}
do_test 3.1 {
db eval { SELECT * FROM x3('one') } {
db eval {
INSERT INTO x3(x3) VALUES('optimize');
}
}
} {}
do_execsql_test 4.0 {
CREATE VIRTUAL TABLE x4 USING fts5(a, detail=%DETAIL%);
INSERT INTO x4 VALUES('one two three');
INSERT INTO x4(rowid, a) VALUES('2', 'one two three');
INSERT INTO x4(rowid, a) VALUES('3.0', 'one two three');
}
do_catchsql_test 4.1 {
INSERT INTO x4(rowid, a) VALUES('four', 'one two three');
} {1 {datatype mismatch}}
do_catchsql_test 4.2 {
UPDATE x4 SET rowid = 'four' WHERE rowid=1;
} {1 {datatype mismatch}}
}
reset_db
do_catchsql_test 4.0 { CREATE VIRTUAL TABLE t1 USING fts5(a,b,c); } {0 {}}
do_catchsql_test 4.1 { DELETE FROM t1 WHERE t1 MATCH 'f*'; } {0 {}}
finish_test
|