3
# The author disclaims copyright to this source code.
5
#*************************************************************************
6
# This file implements regression tests for SQLite library. This
7
# tests creating fts2 tables in an attached database.
9
# $Id: fts2j.test,v 1.1 2007/02/07 01:01:18 shess Exp $
12
set testdir [file dirname $argv0]
13
source $testdir/tester.tcl
15
# If SQLITE_ENABLE_FTS2 is defined, omit this file.
21
# Clean up anything left over from a previous pass.
22
file delete -force test2.db
23
file delete -force test2.db-journal
27
CREATE VIRTUAL TABLE t3 USING fts2(content);
28
INSERT INTO t3 (rowid, content) VALUES(1, "hello world");
32
CREATE VIRTUAL TABLE t1 USING fts2(content);
33
INSERT INTO t1 (rowid, content) VALUES(1, "hello world");
34
INSERT INTO t1 (rowid, content) VALUES(2, "hello there");
35
INSERT INTO t1 (rowid, content) VALUES(3, "cruel world");
38
# This has always worked because the t1_* tables used by fts2 will be
42
ATTACH DATABASE 'test2.db' AS two;
43
SELECT rowid FROM t1 WHERE t1 MATCH 'hello';
47
# Make certain we're detached if there was an error.
48
catch {db eval {DETACH DATABASE two}}
50
# In older code, this appears to work fine, but the t2_* tables used
51
# by fts2 will be created in database 'main' instead of database
52
# 'two'. It appears to work fine because the tables end up being the
53
# defaults, but obviously is badly broken if you hope to use things
54
# other than in the exact same ATTACH setup.
57
ATTACH DATABASE 'test2.db' AS two;
58
CREATE VIRTUAL TABLE two.t2 USING fts2(content);
59
INSERT INTO t2 (rowid, content) VALUES(1, "hello world");
60
INSERT INTO t2 (rowid, content) VALUES(2, "hello there");
61
INSERT INTO t2 (rowid, content) VALUES(3, "cruel world");
62
SELECT rowid FROM t2 WHERE t2 MATCH 'hello';
66
catch {db eval {DETACH DATABASE two}}
68
# In older code, this broke because the fts2 code attempted to create
69
# t3_* tables in database 'main', but they already existed. Normally
70
# this wouldn't happen without t3 itself existing, in which case the
71
# fts2 code would never be called in the first place.
74
ATTACH DATABASE 'test2.db' AS two;
76
CREATE VIRTUAL TABLE two.t3 USING fts2(content);
77
INSERT INTO two.t3 (rowid, content) VALUES(2, "hello there");
78
INSERT INTO two.t3 (rowid, content) VALUES(3, "cruel world");
79
SELECT rowid FROM two.t3 WHERE t3 MATCH 'hello';
84
catch {db eval {DETACH DATABASE two}}
87
file delete -force test2.db