Annotation of embedaddon/sqlite3/test/fts2j.test, revision 1.1.1.1
1.1 misho 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 fts2 tables in an attached database.
8: #
9: # $Id: fts2j.test,v 1.1 2007/02/07 01:01:18 shess Exp $
10: #
11:
12: set testdir [file dirname $argv0]
13: source $testdir/tester.tcl
14:
15: # If SQLITE_ENABLE_FTS2 is defined, omit this file.
16: ifcapable !fts2 {
17: finish_test
18: return
19: }
20:
21: # Clean up anything left over from a previous pass.
22: forcedelete test2.db
23: forcedelete test2.db-journal
24: sqlite3 db2 test2.db
25:
26: db eval {
27: CREATE VIRTUAL TABLE t3 USING fts2(content);
28: INSERT INTO t3 (rowid, content) VALUES(1, "hello world");
29: }
30:
31: db2 eval {
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");
36: }
37:
38: # This has always worked because the t1_* tables used by fts2 will be
39: # the defaults.
40: do_test fts2j-1.1 {
41: execsql {
42: ATTACH DATABASE 'test2.db' AS two;
43: SELECT rowid FROM t1 WHERE t1 MATCH 'hello';
44: DETACH DATABASE two;
45: }
46: } {1 2}
47: # Make certain we're detached if there was an error.
48: catch {db eval {DETACH DATABASE two}}
49:
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.
55: do_test fts2j-1.2 {
56: execsql {
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';
63: DETACH DATABASE two;
64: }
65: } {1 2}
66: catch {db eval {DETACH DATABASE two}}
67:
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.
72: do_test fts2j-1.3 {
73: execsql {
74: ATTACH DATABASE 'test2.db' AS two;
75:
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';
80:
81: DETACH DATABASE two;
82: } db2
83: } {2}
84: catch {db eval {DETACH DATABASE two}}
85:
86: catch {db2 close}
87: forcedelete test2.db
88:
89: finish_test
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>