CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
fts3aj.test88 linesDownload Raw Back to test
1# 2007 February 62#3# The author disclaims copyright to this source code.4#5#*************************************************************************6# This file implements regression tests for SQLite library.  This7# tests creating fts3 tables in an attached database.8#9 10set testdir [file dirname $argv0]11source $testdir/tester.tcl12 13# If SQLITE_ENABLE_FTS3 is defined, omit this file.14ifcapable !fts3 {15  finish_test16  return17}18 19# Clean up anything left over from a previous pass.20forcedelete test2.db21forcedelete test2.db-journal22sqlite3 db2 test2.db23 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 be37# 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 used49# by fts3 will be created in database 'main' instead of database50# 'two'.  It appears to work fine because the tables end up being the51# defaults, but obviously is badly broken if you hope to use things52# 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 create67# t3_* tables in database 'main', but they already existed.  Normally68# this wouldn't happen without t3 itself existing, in which case the69# 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  } db281} {2}82catch {db eval {DETACH DATABASE two}}83 84catch {db2 close}85forcedelete test2.db86 87finish_test88