3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #*************************************************************************
11 # This file implements regression tests for SQLite library. The focus
12 # of this script is testing the FTS1 module rename functionality. Mostly
13 # copied from fts2o.test.
15 # $Id: fts1o.test,v 1.2 2007/08/30 20:01:33 shess Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 # If SQLITE_ENABLE_FTS1 is not defined, omit this file.
28 CREATE VIRTUAL TABLE t1 USING fts1(a, b, c);
29 INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two');
32 #---------------------------------------------------------------------
33 # Test that it is possible to rename an fts1 table.
36 execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
37 } {t1 t1_content t1_term}
39 execsql { ALTER TABLE t1 RENAME to fts_t1; }
42 execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
43 } {1 {one three <b>four</b>}}
45 execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
46 } {fts_t1 fts_t1_content fts_t1_term}
48 # See what happens when renaming the fts1 table fails.
52 CREATE TABLE t1_term(a, b, c);
53 ALTER TABLE fts_t1 RENAME to t1;
55 } {1 {SQL logic error}}
57 execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
58 } {1 {one three <b>four</b>}}
60 execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
61 } {fts_t1 fts_t1_content fts_t1_term t1_term}
63 # See what happens when renaming the fts1 table fails inside a transaction.
68 INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two');
73 ALTER TABLE fts_t1 RENAME to t1;
75 } {1 {SQL logic error}}
76 # NOTE(shess) rowid AS rowid to defeat caching. Otherwise, this
77 # seg-faults, I suspect that there's something up with a stale
78 # virtual-table reference, but I'm not quite sure how it happens here
79 # but not for fts2o.test.
81 execsql { SELECT rowid AS rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
82 } {1 {one three <b>four</b>}}
84 execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
85 } {fts_t1 fts_t1_content fts_t1_term t1_term}
88 execsql {SELECT a FROM fts_t1}
89 } {{one three four} {one two three}}
91 execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; }
92 } {{one three four} {one four} {one four two}}
94 #---------------------------------------------------------------------
95 # Test that it is possible to rename an fts1 table in an attached
98 forcedelete test2.db test2.db-journal
103 ALTER TABLE fts_t1 RENAME to t1;
104 SELECT a, b, c FROM t1 WHERE c MATCH 'two';
106 } {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
110 ATTACH 'test2.db' AS aux;
111 CREATE VIRTUAL TABLE aux.t1 USING fts1(a, b, c);
112 INSERT INTO aux.t1(a, b, c) VALUES(
113 'neung song sahm', 'neung see', 'neung see song'
119 execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; }
120 } {{neung song sahm} {neung see} {neung see song}}
123 execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
124 } {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
127 execsql { ALTER TABLE aux.t1 RENAME TO t2 }
131 execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; }
132 } {{neung song sahm} {neung see} {neung see song}}
135 execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
136 } {{one three four} {one four} {one four two} {one two three} {one four} {one two}}