sl@0
|
1 |
# 2008 July 29
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#*************************************************************************
|
sl@0
|
11 |
# These tests exercise the various types of fts2 cursors.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# $Id: fts2r.test,v 1.1 2008/07/29 20:38:18 shess Exp $
|
sl@0
|
14 |
#
|
sl@0
|
15 |
|
sl@0
|
16 |
set testdir [file dirname $argv0]
|
sl@0
|
17 |
source $testdir/tester.tcl
|
sl@0
|
18 |
|
sl@0
|
19 |
# If SQLITE_ENABLE_FTS2 is not defined, omit this file.
|
sl@0
|
20 |
ifcapable !fts2 {
|
sl@0
|
21 |
finish_test
|
sl@0
|
22 |
return
|
sl@0
|
23 |
}
|
sl@0
|
24 |
|
sl@0
|
25 |
#*************************************************************************
|
sl@0
|
26 |
# Test table scan (QUERY_GENERIC). This kind of query happens for
|
sl@0
|
27 |
# queries with no WHERE clause, or for WHERE clauses which cannot be
|
sl@0
|
28 |
# satisfied by an index.
|
sl@0
|
29 |
db eval {
|
sl@0
|
30 |
DROP TABLE IF EXISTS t1;
|
sl@0
|
31 |
CREATE VIRTUAL TABLE t1 USING fts2(c);
|
sl@0
|
32 |
INSERT INTO t1 (rowid, c) VALUES (1, 'This is a test');
|
sl@0
|
33 |
INSERT INTO t1 (rowid, c) VALUES (2, 'That was a test');
|
sl@0
|
34 |
INSERT INTO t1 (rowid, c) VALUES (3, 'This is a test');
|
sl@0
|
35 |
}
|
sl@0
|
36 |
|
sl@0
|
37 |
do_test fts2e-1.1 {
|
sl@0
|
38 |
execsql {
|
sl@0
|
39 |
SELECT rowid FROM t1 ORDER BY rowid;
|
sl@0
|
40 |
}
|
sl@0
|
41 |
} {1 2 3}
|
sl@0
|
42 |
|
sl@0
|
43 |
do_test fts2e-1.2 {
|
sl@0
|
44 |
execsql {
|
sl@0
|
45 |
SELECT rowid FROM t1 WHERE c LIKE '%test' ORDER BY rowid;
|
sl@0
|
46 |
}
|
sl@0
|
47 |
} {1 2 3}
|
sl@0
|
48 |
|
sl@0
|
49 |
do_test fts2e-1.3 {
|
sl@0
|
50 |
execsql {
|
sl@0
|
51 |
SELECT rowid FROM t1 WHERE c LIKE 'That%' ORDER BY rowid;
|
sl@0
|
52 |
}
|
sl@0
|
53 |
} {2}
|
sl@0
|
54 |
|
sl@0
|
55 |
#*************************************************************************
|
sl@0
|
56 |
# Test lookup by rowid (QUERY_ROWID). This kind of query happens for
|
sl@0
|
57 |
# queries which select by the rowid implicit index.
|
sl@0
|
58 |
db eval {
|
sl@0
|
59 |
DROP TABLE IF EXISTS t1;
|
sl@0
|
60 |
DROP TABLE IF EXISTS t2;
|
sl@0
|
61 |
CREATE VIRTUAL TABLE t1 USING fts2(c);
|
sl@0
|
62 |
CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
|
sl@0
|
63 |
INSERT INTO t2 VALUES (null, 10);
|
sl@0
|
64 |
INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
|
sl@0
|
65 |
INSERT INTO t2 VALUES (null, 5);
|
sl@0
|
66 |
INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'That was a test');
|
sl@0
|
67 |
INSERT INTO t2 VALUES (null, 20);
|
sl@0
|
68 |
INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
|
sl@0
|
69 |
}
|
sl@0
|
70 |
|
sl@0
|
71 |
# TODO(shess): This actually is doing QUERY_GENERIC? I'd have
|
sl@0
|
72 |
# expected QUERY_ROWID in this case, as for a very large table the
|
sl@0
|
73 |
# full scan is less efficient.
|
sl@0
|
74 |
do_test fts2e-2.1 {
|
sl@0
|
75 |
execsql {
|
sl@0
|
76 |
SELECT rowid FROM t1 WHERE rowid in (1, 2, 10);
|
sl@0
|
77 |
}
|
sl@0
|
78 |
} {1 2}
|
sl@0
|
79 |
|
sl@0
|
80 |
do_test fts2e-2.2 {
|
sl@0
|
81 |
execsql {
|
sl@0
|
82 |
SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
} {2 5 1 10 3 20}
|
sl@0
|
85 |
|
sl@0
|
86 |
do_test fts2e-2.3 {
|
sl@0
|
87 |
execsql {
|
sl@0
|
88 |
SELECT t1.rowid, weight FROM t1, t2
|
sl@0
|
89 |
WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
} {1 10 3 20}
|
sl@0
|
92 |
|
sl@0
|
93 |
#*************************************************************************
|
sl@0
|
94 |
# Test lookup by MATCH (QUERY_FULLTEXT). This is the fulltext index.
|
sl@0
|
95 |
db eval {
|
sl@0
|
96 |
DROP TABLE IF EXISTS t1;
|
sl@0
|
97 |
DROP TABLE IF EXISTS t2;
|
sl@0
|
98 |
CREATE VIRTUAL TABLE t1 USING fts2(c);
|
sl@0
|
99 |
CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
|
sl@0
|
100 |
INSERT INTO t2 VALUES (null, 10);
|
sl@0
|
101 |
INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
|
sl@0
|
102 |
INSERT INTO t2 VALUES (null, 5);
|
sl@0
|
103 |
INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'That was a test');
|
sl@0
|
104 |
INSERT INTO t2 VALUES (null, 20);
|
sl@0
|
105 |
INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
do_test fts2e-3.1 {
|
sl@0
|
109 |
execsql {
|
sl@0
|
110 |
SELECT rowid FROM t1 WHERE t1 MATCH 'this' ORDER BY rowid;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
} {1 3}
|
sl@0
|
113 |
|
sl@0
|
114 |
do_test fts2e-3.2 {
|
sl@0
|
115 |
execsql {
|
sl@0
|
116 |
SELECT t1.rowid, weight FROM t1, t2
|
sl@0
|
117 |
WHERE t1 MATCH 'this' AND t1.rowid = t2.id ORDER BY weight;
|
sl@0
|
118 |
}
|
sl@0
|
119 |
} {1 10 3 20}
|
sl@0
|
120 |
|
sl@0
|
121 |
finish_test
|