Add a test for the fixes on this branch.
[sqlite.git] / test / fts3aj.test
blob0c89691162434d08ea00a364c63d9bcac8e6ade8
1 # 2007 February 6
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.
14 ifcapable !fts3 {
15   finish_test
16   return
19 # Clean up anything left over from a previous pass.
20 forcedelete test2.db
21 forcedelete test2.db-journal
22 sqlite3 db2 test2.db
24 db eval {
25   CREATE VIRTUAL TABLE t3 USING fts3(content);
26   INSERT INTO t3 (rowid, content) VALUES(1, 'hello world');
29 db2 eval {
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
37 # the defaults.
38 do_test fts3aj-1.1 {
39   execsql {
40     ATTACH DATABASE 'test2.db' AS two;
41     SELECT rowid FROM t1 WHERE t1 MATCH 'hello';
42     DETACH DATABASE two;
43   }
44 } {1 2}
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.
53 do_test fts3aj-1.2 {
54   execsql {
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';
61     DETACH DATABASE two;
62   }
63 } {1 2}
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.
70 do_test fts3aj-1.3 {
71   execsql {
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';
79     DETACH DATABASE two;
80   } db2
81 } {2}
82 catch {db eval {DETACH DATABASE two}}
84 catch {db2 close}
85 forcedelete test2.db
87 finish_test