sl@0
|
1 |
# 2007 March 9
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code.
|
sl@0
|
4 |
#
|
sl@0
|
5 |
#*************************************************************************
|
sl@0
|
6 |
# This file implements regression tests for SQLite library. These
|
sl@0
|
7 |
# make sure that fts2 insertion buffering is fully transparent when
|
sl@0
|
8 |
# using transactions.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
# $Id: fts2k.test,v 1.2 2007/08/10 23:47:04 shess Exp $
|
sl@0
|
11 |
#
|
sl@0
|
12 |
|
sl@0
|
13 |
set testdir [file dirname $argv0]
|
sl@0
|
14 |
source $testdir/tester.tcl
|
sl@0
|
15 |
|
sl@0
|
16 |
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
|
sl@0
|
17 |
ifcapable !fts2 {
|
sl@0
|
18 |
finish_test
|
sl@0
|
19 |
return
|
sl@0
|
20 |
}
|
sl@0
|
21 |
|
sl@0
|
22 |
db eval {
|
sl@0
|
23 |
CREATE VIRTUAL TABLE t1 USING fts2(content);
|
sl@0
|
24 |
INSERT INTO t1 (rowid, content) VALUES(1, "hello world");
|
sl@0
|
25 |
INSERT INTO t1 (rowid, content) VALUES(2, "hello there");
|
sl@0
|
26 |
INSERT INTO t1 (rowid, content) VALUES(3, "cruel world");
|
sl@0
|
27 |
}
|
sl@0
|
28 |
|
sl@0
|
29 |
# Test that possibly-buffered inserts went through after commit.
|
sl@0
|
30 |
do_test fts2k-1.1 {
|
sl@0
|
31 |
execsql {
|
sl@0
|
32 |
BEGIN TRANSACTION;
|
sl@0
|
33 |
INSERT INTO t1 (rowid, content) VALUES(4, "false world");
|
sl@0
|
34 |
INSERT INTO t1 (rowid, content) VALUES(5, "false door");
|
sl@0
|
35 |
COMMIT TRANSACTION;
|
sl@0
|
36 |
SELECT rowid FROM t1 WHERE t1 MATCH 'world';
|
sl@0
|
37 |
}
|
sl@0
|
38 |
} {1 3 4}
|
sl@0
|
39 |
|
sl@0
|
40 |
# Test that buffered inserts are seen by selects in the same
|
sl@0
|
41 |
# transaction.
|
sl@0
|
42 |
do_test fts2k-1.2 {
|
sl@0
|
43 |
execsql {
|
sl@0
|
44 |
BEGIN TRANSACTION;
|
sl@0
|
45 |
INSERT INTO t1 (rowid, content) VALUES(6, "another world");
|
sl@0
|
46 |
INSERT INTO t1 (rowid, content) VALUES(7, "another test");
|
sl@0
|
47 |
SELECT rowid FROM t1 WHERE t1 MATCH 'world';
|
sl@0
|
48 |
COMMIT TRANSACTION;
|
sl@0
|
49 |
}
|
sl@0
|
50 |
} {1 3 4 6}
|
sl@0
|
51 |
|
sl@0
|
52 |
# Test that buffered inserts are seen within a transaction. This is
|
sl@0
|
53 |
# really the same test as 1.2.
|
sl@0
|
54 |
do_test fts2k-1.3 {
|
sl@0
|
55 |
execsql {
|
sl@0
|
56 |
BEGIN TRANSACTION;
|
sl@0
|
57 |
INSERT INTO t1 (rowid, content) VALUES(8, "second world");
|
sl@0
|
58 |
INSERT INTO t1 (rowid, content) VALUES(9, "second sight");
|
sl@0
|
59 |
SELECT rowid FROM t1 WHERE t1 MATCH 'world';
|
sl@0
|
60 |
ROLLBACK TRANSACTION;
|
sl@0
|
61 |
}
|
sl@0
|
62 |
} {1 3 4 6 8}
|
sl@0
|
63 |
|
sl@0
|
64 |
# Double-check that the previous result doesn't persist past the
|
sl@0
|
65 |
# rollback!
|
sl@0
|
66 |
do_test fts2k-1.4 {
|
sl@0
|
67 |
execsql {
|
sl@0
|
68 |
SELECT rowid FROM t1 WHERE t1 MATCH 'world';
|
sl@0
|
69 |
}
|
sl@0
|
70 |
} {1 3 4 6}
|
sl@0
|
71 |
|
sl@0
|
72 |
# Test it all together.
|
sl@0
|
73 |
do_test fts2k-1.5 {
|
sl@0
|
74 |
execsql {
|
sl@0
|
75 |
BEGIN TRANSACTION;
|
sl@0
|
76 |
INSERT INTO t1 (rowid, content) VALUES(10, "second world");
|
sl@0
|
77 |
INSERT INTO t1 (rowid, content) VALUES(11, "second sight");
|
sl@0
|
78 |
ROLLBACK TRANSACTION;
|
sl@0
|
79 |
SELECT rowid FROM t1 WHERE t1 MATCH 'world';
|
sl@0
|
80 |
}
|
sl@0
|
81 |
} {1 3 4 6}
|
sl@0
|
82 |
|
sl@0
|
83 |
# Test that the obvious case works.
|
sl@0
|
84 |
do_test fts2k-1.6 {
|
sl@0
|
85 |
execsql {
|
sl@0
|
86 |
BEGIN;
|
sl@0
|
87 |
INSERT INTO t1 (rowid, content) VALUES(12, "third world");
|
sl@0
|
88 |
COMMIT;
|
sl@0
|
89 |
SELECT rowid FROM t1 WHERE t1 MATCH 'third';
|
sl@0
|
90 |
}
|
sl@0
|
91 |
} {12}
|
sl@0
|
92 |
|
sl@0
|
93 |
# This is exactly the same as the previous test, except that older
|
sl@0
|
94 |
# code loses the INSERT due to an SQLITE_SCHEMA error.
|
sl@0
|
95 |
do_test fts2k-1.7 {
|
sl@0
|
96 |
execsql {
|
sl@0
|
97 |
BEGIN;
|
sl@0
|
98 |
INSERT INTO t1 (rowid, content) VALUES(13, "third dimension");
|
sl@0
|
99 |
CREATE TABLE x (c);
|
sl@0
|
100 |
COMMIT;
|
sl@0
|
101 |
SELECT rowid FROM t1 WHERE t1 MATCH 'dimension';
|
sl@0
|
102 |
}
|
sl@0
|
103 |
} {13}
|
sl@0
|
104 |
|
sl@0
|
105 |
finish_test
|