3 # The author disclaims copyright to this source code.
5 #*************************************************************************
6 # This file implements regression tests for SQLite library. This
7 # tests creating fts3 tables in an attached database.
10 set testdir [file dirname $argv0]
11 source $testdir/tester.tcl
13 # If SQLITE_ENABLE_FTS3 is defined, omit this file.
19 # Clean up anything left over from a previous pass.
21 forcedelete test2.db-journal
25 CREATE VIRTUAL TABLE t3 USING fts3(content);
26 INSERT INTO t3 (rowid, content) VALUES(1, 'hello world');
30 CREATE VIRTUAL TABLE t1 USING fts3(content);
31 INSERT INTO t1 (rowid, content) VALUES(1, 'hello world');
32 INSERT INTO t1 (rowid, content) VALUES(2, 'hello there');
33 INSERT INTO t1 (rowid, content) VALUES(3, 'cruel world');
36 # This has always worked because the t1_* tables used by fts3 will be
40 ATTACH DATABASE 'test2.db' AS two;
41 SELECT rowid FROM t1 WHERE t1 MATCH 'hello';
45 # Make certain we're detached if there was an error.
46 catch {db eval {DETACH DATABASE two}}
48 # In older code, this appears to work fine, but the t2_* tables used
49 # by fts3 will be created in database 'main' instead of database
50 # 'two'. It appears to work fine because the tables end up being the
51 # defaults, but obviously is badly broken if you hope to use things
52 # other than in the exact same ATTACH setup.
55 ATTACH DATABASE 'test2.db' AS two;
56 CREATE VIRTUAL TABLE two.t2 USING fts3(content);
57 INSERT INTO t2 (rowid, content) VALUES(1, 'hello world');
58 INSERT INTO t2 (rowid, content) VALUES(2, 'hello there');
59 INSERT INTO t2 (rowid, content) VALUES(3, 'cruel world');
60 SELECT rowid FROM t2 WHERE t2 MATCH 'hello';
64 catch {db eval {DETACH DATABASE two}}
66 # In older code, this broke because the fts3 code attempted to create
67 # t3_* tables in database 'main', but they already existed. Normally
68 # this wouldn't happen without t3 itself existing, in which case the
69 # fts3 code would never be called in the first place.
72 ATTACH DATABASE 'test2.db' AS two;
74 CREATE VIRTUAL TABLE two.t3 USING fts3(content);
75 INSERT INTO two.t3 (rowid, content) VALUES(2, 'hello there');
76 INSERT INTO two.t3 (rowid, content) VALUES(3, 'cruel world');
77 SELECT rowid FROM two.t3 WHERE t3 MATCH 'hello';
82 catch {db eval {DETACH DATABASE two}}