sl@0: # 2007 February 6 sl@0: # sl@0: # The author disclaims copyright to this source code. sl@0: # sl@0: #************************************************************************* sl@0: # This file implements regression tests for SQLite library. This sl@0: # tests creating fts3 tables in an attached database. sl@0: # sl@0: # $Id: fts3aj.test,v 1.1 2007/08/20 17:38:42 shess Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # If SQLITE_ENABLE_FTS3 is defined, omit this file. sl@0: ifcapable !fts3 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: # Clean up anything left over from a previous pass. sl@0: file delete -force test2.db sl@0: file delete -force test2.db-journal sl@0: sqlite3 db2 test2.db sl@0: sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t3 USING fts3(content); sl@0: INSERT INTO t3 (rowid, content) VALUES(1, "hello world"); sl@0: } sl@0: sl@0: db2 eval { sl@0: CREATE VIRTUAL TABLE t1 USING fts3(content); sl@0: INSERT INTO t1 (rowid, content) VALUES(1, "hello world"); sl@0: INSERT INTO t1 (rowid, content) VALUES(2, "hello there"); sl@0: INSERT INTO t1 (rowid, content) VALUES(3, "cruel world"); sl@0: } sl@0: sl@0: # This has always worked because the t1_* tables used by fts3 will be sl@0: # the defaults. sl@0: do_test fts3aj-1.1 { sl@0: execsql { sl@0: ATTACH DATABASE 'test2.db' AS two; sl@0: SELECT rowid FROM t1 WHERE t1 MATCH 'hello'; sl@0: DETACH DATABASE two; sl@0: } sl@0: } {1 2} sl@0: # Make certain we're detached if there was an error. sl@0: catch {db eval {DETACH DATABASE two}} sl@0: sl@0: # In older code, this appears to work fine, but the t2_* tables used sl@0: # by fts3 will be created in database 'main' instead of database sl@0: # 'two'. It appears to work fine because the tables end up being the sl@0: # defaults, but obviously is badly broken if you hope to use things sl@0: # other than in the exact same ATTACH setup. sl@0: do_test fts3aj-1.2 { sl@0: execsql { sl@0: ATTACH DATABASE 'test2.db' AS two; sl@0: CREATE VIRTUAL TABLE two.t2 USING fts3(content); sl@0: INSERT INTO t2 (rowid, content) VALUES(1, "hello world"); sl@0: INSERT INTO t2 (rowid, content) VALUES(2, "hello there"); sl@0: INSERT INTO t2 (rowid, content) VALUES(3, "cruel world"); sl@0: SELECT rowid FROM t2 WHERE t2 MATCH 'hello'; sl@0: DETACH DATABASE two; sl@0: } sl@0: } {1 2} sl@0: catch {db eval {DETACH DATABASE two}} sl@0: sl@0: # In older code, this broke because the fts3 code attempted to create sl@0: # t3_* tables in database 'main', but they already existed. Normally sl@0: # this wouldn't happen without t3 itself existing, in which case the sl@0: # fts3 code would never be called in the first place. sl@0: do_test fts3aj-1.3 { sl@0: execsql { sl@0: ATTACH DATABASE 'test2.db' AS two; sl@0: sl@0: CREATE VIRTUAL TABLE two.t3 USING fts3(content); sl@0: INSERT INTO two.t3 (rowid, content) VALUES(2, "hello there"); sl@0: INSERT INTO two.t3 (rowid, content) VALUES(3, "cruel world"); sl@0: SELECT rowid FROM two.t3 WHERE t3 MATCH 'hello'; sl@0: sl@0: DETACH DATABASE two; sl@0: } db2 sl@0: } {2} sl@0: catch {db eval {DETACH DATABASE two}} sl@0: sl@0: catch {db2 close} sl@0: file delete -force test2.db sl@0: sl@0: finish_test