xref: /sqlite-3.40.0/test/fts3aj.test (revision 7d44b22d)
1# 2007 February 6
2#
3# The author disclaims copyright to this source code.
4#
5#*************************************************************************
6# This file implements regression tests for SQLite library.  This
7# tests creating fts3 tables in an attached database.
8#
9
10set testdir [file dirname $argv0]
11source $testdir/tester.tcl
12
13# If SQLITE_ENABLE_FTS3 is defined, omit this file.
14ifcapable !fts3 {
15  finish_test
16  return
17}
18
19# Clean up anything left over from a previous pass.
20forcedelete test2.db
21forcedelete test2.db-journal
22sqlite3 db2 test2.db
23
24db eval {
25  CREATE VIRTUAL TABLE t3 USING fts3(content);
26  INSERT INTO t3 (rowid, content) VALUES(1, 'hello world');
27}
28
29db2 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');
34}
35
36# This has always worked because the t1_* tables used by fts3 will be
37# the defaults.
38do_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.
46catch {db eval {DETACH DATABASE two}}
47
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.
53do_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}
64catch {db eval {DETACH DATABASE two}}
65
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.
70do_test fts3aj-1.3 {
71  execsql {
72    ATTACH DATABASE 'test2.db' AS two;
73
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';
78
79    DETACH DATABASE two;
80  } db2
81} {2}
82catch {db eval {DETACH DATABASE two}}
83
84catch {db2 close}
85forcedelete test2.db
86
87finish_test
88