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
|
# 2015 April 28
#
# 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 focuses on testing the planner (xBestIndex function).
#
source [file join [file dirname [info script]] fts5_common.tcl]
set testprefix fts5restart
# If SQLITE_ENABLE_FTS5 is defined, omit this file.
ifcapable !fts5 {
finish_test
return
}
do_execsql_test 1.0 {
CREATE VIRTUAL TABLE f1 USING fts5(ff);
}
#-------------------------------------------------------------------------
# Run the 'optimize' command. Check that it does not disturb ongoing
# full-text queries.
#
do_test 1.1 {
for {set i 1} {$i < 1000} {incr i} {
execsql { INSERT INTO f1 VALUES('a b c d e') }
lappend lRowid $i
}
} {}
do_execsql_test 1.2 {
SELECT rowid FROM f1 WHERE f1 MATCH 'c';
} $lRowid
do_test 1.3 {
set res [list]
db eval { SELECT rowid FROM f1 WHERE f1 MATCH 'c' } {
if {$rowid == 100} {
execsql { INSERT INTO f1(f1) VALUES('optimize') }
}
lappend res $rowid
}
set res
} $lRowid
do_test 1.4.1 {
sqlite3 db2 test.db
set res [list]
db2 eval { SELECT rowid FROM f1 WHERE f1 MATCH 'c' } {
if {$rowid == 100} {
set cres [catchsql { INSERT INTO f1(f1) VALUES('optimize') }]
}
lappend res $rowid
}
set res
} $lRowid
do_test 1.4.2 {
db2 close
set cres
} {1 {database is locked}}
#-------------------------------------------------------------------------
# Open a couple of cursors. Then close them in the same order.
#
do_test 2.1 {
set ::s1 [sqlite3_prepare db "SELECT rowid FROM f1 WHERE f1 MATCH 'b'" -1 X]
set ::s2 [sqlite3_prepare db "SELECT rowid FROM f1 WHERE f1 MATCH 'c'" -1 X]
sqlite3_step $::s1
} {SQLITE_ROW}
do_test 2.2 {
sqlite3_step $::s2
} {SQLITE_ROW}
do_test 2.1 {
sqlite3_finalize $::s1
sqlite3_finalize $::s2
} {SQLITE_OK}
#-------------------------------------------------------------------------
# Copy data between two FTS5 tables.
#
do_execsql_test 3.1 {
CREATE VIRTUAL TABLE f2 USING fts5(gg);
INSERT INTO f2 SELECT ff FROM f1 WHERE f1 MATCH 'b+c+d';
}
do_execsql_test 3.2 {
SELECT rowid FROM f2 WHERE f2 MATCH 'a+b+c+d+e'
} $lRowid
#-------------------------------------------------------------------------
# Remove the row that an FTS5 cursor is currently pointing to. And
# various other similar things. Check that this does not disturb
# ongoing scans.
#
do_execsql_test 4.0 {
CREATE VIRTUAL TABLE n4 USING fts5(n);
INSERT INTO n4(rowid, n) VALUES(100, '1 2 3 4 5');
INSERT INTO n4(rowid, n) VALUES(200, '1 2 3 4');
INSERT INTO n4(rowid, n) VALUES(300, '2 3 4');
INSERT INTO n4(rowid, n) VALUES(400, '2 3');
INSERT INTO n4(rowid, n) VALUES(500, '3');
}
do_test 4.1 {
set res [list]
db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' } {
if {$rowid==300} {
execsql { DELETE FROM n4 WHERE rowid=300 }
}
lappend res $rowid
}
set res
} {100 200 300 400 500}
do_test 4.2 {
execsql { INSERT INTO n4(rowid, n) VALUES(300, '2 3 4') }
set res [list]
db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' ORDER BY rowid DESC} {
if {$rowid==300} {
execsql { DELETE FROM n4 WHERE rowid=300 }
}
lappend res $rowid
}
set res
} {500 400 300 200 100}
do_test 4.3 {
execsql { INSERT INTO n4(rowid, n) VALUES(300, '2 3 4') }
set res [list]
db eval { SELECT rowid FROM n4 WHERE n4 MATCH '3' ORDER BY rowid DESC} {
if {$rowid==300} {
execsql { DELETE FROM n4 }
}
lappend res $rowid
}
set res
} {500 400 300}
finish_test
|