1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fts2j.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,89 @@
1.4 +# 2007 February 6
1.5 +#
1.6 +# The author disclaims copyright to this source code.
1.7 +#
1.8 +#*************************************************************************
1.9 +# This file implements regression tests for SQLite library. This
1.10 +# tests creating fts2 tables in an attached database.
1.11 +#
1.12 +# $Id: fts2j.test,v 1.1 2007/02/07 01:01:18 shess Exp $
1.13 +#
1.14 +
1.15 +set testdir [file dirname $argv0]
1.16 +source $testdir/tester.tcl
1.17 +
1.18 +# If SQLITE_ENABLE_FTS2 is defined, omit this file.
1.19 +ifcapable !fts2 {
1.20 + finish_test
1.21 + return
1.22 +}
1.23 +
1.24 +# Clean up anything left over from a previous pass.
1.25 +file delete -force test2.db
1.26 +file delete -force test2.db-journal
1.27 +sqlite3 db2 test2.db
1.28 +
1.29 +db eval {
1.30 + CREATE VIRTUAL TABLE t3 USING fts2(content);
1.31 + INSERT INTO t3 (rowid, content) VALUES(1, "hello world");
1.32 +}
1.33 +
1.34 +db2 eval {
1.35 + CREATE VIRTUAL TABLE t1 USING fts2(content);
1.36 + INSERT INTO t1 (rowid, content) VALUES(1, "hello world");
1.37 + INSERT INTO t1 (rowid, content) VALUES(2, "hello there");
1.38 + INSERT INTO t1 (rowid, content) VALUES(3, "cruel world");
1.39 +}
1.40 +
1.41 +# This has always worked because the t1_* tables used by fts2 will be
1.42 +# the defaults.
1.43 +do_test fts2j-1.1 {
1.44 + execsql {
1.45 + ATTACH DATABASE 'test2.db' AS two;
1.46 + SELECT rowid FROM t1 WHERE t1 MATCH 'hello';
1.47 + DETACH DATABASE two;
1.48 + }
1.49 +} {1 2}
1.50 +# Make certain we're detached if there was an error.
1.51 +catch {db eval {DETACH DATABASE two}}
1.52 +
1.53 +# In older code, this appears to work fine, but the t2_* tables used
1.54 +# by fts2 will be created in database 'main' instead of database
1.55 +# 'two'. It appears to work fine because the tables end up being the
1.56 +# defaults, but obviously is badly broken if you hope to use things
1.57 +# other than in the exact same ATTACH setup.
1.58 +do_test fts2j-1.2 {
1.59 + execsql {
1.60 + ATTACH DATABASE 'test2.db' AS two;
1.61 + CREATE VIRTUAL TABLE two.t2 USING fts2(content);
1.62 + INSERT INTO t2 (rowid, content) VALUES(1, "hello world");
1.63 + INSERT INTO t2 (rowid, content) VALUES(2, "hello there");
1.64 + INSERT INTO t2 (rowid, content) VALUES(3, "cruel world");
1.65 + SELECT rowid FROM t2 WHERE t2 MATCH 'hello';
1.66 + DETACH DATABASE two;
1.67 + }
1.68 +} {1 2}
1.69 +catch {db eval {DETACH DATABASE two}}
1.70 +
1.71 +# In older code, this broke because the fts2 code attempted to create
1.72 +# t3_* tables in database 'main', but they already existed. Normally
1.73 +# this wouldn't happen without t3 itself existing, in which case the
1.74 +# fts2 code would never be called in the first place.
1.75 +do_test fts2j-1.3 {
1.76 + execsql {
1.77 + ATTACH DATABASE 'test2.db' AS two;
1.78 +
1.79 + CREATE VIRTUAL TABLE two.t3 USING fts2(content);
1.80 + INSERT INTO two.t3 (rowid, content) VALUES(2, "hello there");
1.81 + INSERT INTO two.t3 (rowid, content) VALUES(3, "cruel world");
1.82 + SELECT rowid FROM two.t3 WHERE t3 MATCH 'hello';
1.83 +
1.84 + DETACH DATABASE two;
1.85 + } db2
1.86 +} {2}
1.87 +catch {db eval {DETACH DATABASE two}}
1.88 +
1.89 +catch {db2 close}
1.90 +file delete -force test2.db
1.91 +
1.92 +finish_test