sl@0: # 2007 July 24 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #************************************************************************* sl@0: # This file implements regression tests for SQLite library. The focus sl@0: # of this script is testing the FTS1 module rename functionality. Mostly sl@0: # copied from fts2o.test. sl@0: # sl@0: # $Id: fts1o.test,v 1.2 2007/08/30 20:01:33 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_FTS1 is not defined, omit this file. sl@0: ifcapable !fts1 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t1 USING fts1(a, b, c); sl@0: INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two'); sl@0: } sl@0: sl@0: #--------------------------------------------------------------------- sl@0: # Test that it is possible to rename an fts1 table. sl@0: # sl@0: do_test fts1o-1.1 { sl@0: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} sl@0: } {t1 t1_content t1_term} sl@0: do_test fts1o-1.2 { sl@0: execsql { ALTER TABLE t1 RENAME to fts_t1; } sl@0: } {} sl@0: do_test fts1o-1.3 { sl@0: execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } sl@0: } {1 {one three four}} sl@0: do_test fts1o-1.4 { sl@0: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} sl@0: } {fts_t1 fts_t1_content fts_t1_term} sl@0: sl@0: # See what happens when renaming the fts1 table fails. sl@0: # sl@0: do_test fts1o-2.1 { sl@0: catchsql { sl@0: CREATE TABLE t1_term(a, b, c); sl@0: ALTER TABLE fts_t1 RENAME to t1; sl@0: } sl@0: } {1 {SQL logic error or missing database}} sl@0: do_test fts1o-2.2 { sl@0: execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } sl@0: } {1 {one three four}} sl@0: do_test fts1o-2.3 { sl@0: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} sl@0: } {fts_t1 fts_t1_content fts_t1_term t1_term} sl@0: sl@0: # See what happens when renaming the fts1 table fails inside a transaction. sl@0: # sl@0: do_test fts1o-3.1 { sl@0: execsql { sl@0: BEGIN; sl@0: INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two'); sl@0: } sl@0: } {} sl@0: do_test fts1o-3.2 { sl@0: catchsql { sl@0: ALTER TABLE fts_t1 RENAME to t1; sl@0: } sl@0: } {1 {SQL logic error or missing database}} sl@0: # NOTE(shess) rowid AS rowid to defeat caching. Otherwise, this sl@0: # seg-faults, I suspect that there's something up with a stale sl@0: # virtual-table reference, but I'm not quite sure how it happens here sl@0: # but not for fts2o.test. sl@0: do_test fts1o-3.3 { sl@0: execsql { SELECT rowid AS rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; } sl@0: } {1 {one three four}} sl@0: do_test fts1o-3.4 { sl@0: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} sl@0: } {fts_t1 fts_t1_content fts_t1_term t1_term} sl@0: do_test fts1o-3.5 { sl@0: execsql COMMIT sl@0: execsql {SELECT a FROM fts_t1} sl@0: } {{one three four} {one two three}} sl@0: do_test fts1o-3.6 { sl@0: execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; } sl@0: } {{one three four} {one four} {one four two}} sl@0: sl@0: #--------------------------------------------------------------------- sl@0: # Test that it is possible to rename an fts1 table in an attached sl@0: # database. sl@0: # sl@0: file delete -force test2.db test2.db-journal sl@0: sl@0: do_test fts1o-4.1 { sl@0: execsql { sl@0: DROP TABLE t1_term; sl@0: ALTER TABLE fts_t1 RENAME to t1; sl@0: SELECT a, b, c FROM t1 WHERE c MATCH 'two'; sl@0: } sl@0: } {{one three four} {one four} {one four two} {one two three} {one four} {one two}} sl@0: sl@0: do_test fts1o-4.2 { sl@0: execsql { sl@0: ATTACH 'test2.db' AS aux; sl@0: CREATE VIRTUAL TABLE aux.t1 USING fts1(a, b, c); sl@0: INSERT INTO aux.t1(a, b, c) VALUES( sl@0: 'neung song sahm', 'neung see', 'neung see song' sl@0: ); sl@0: } sl@0: } {} sl@0: sl@0: do_test fts1o-4.3 { sl@0: execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; } sl@0: } {{neung song sahm} {neung see} {neung see song}} sl@0: sl@0: do_test fts1o-4.4 { sl@0: execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } sl@0: } {{one three four} {one four} {one four two} {one two three} {one four} {one two}} sl@0: sl@0: do_test fts1o-4.5 { sl@0: execsql { ALTER TABLE aux.t1 RENAME TO t2 } sl@0: } {} sl@0: sl@0: do_test fts1o-4.6 { sl@0: execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; } sl@0: } {{neung song sahm} {neung see} {neung see song}} sl@0: sl@0: do_test fts1o-4.7 { sl@0: execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } sl@0: } {{one three four} {one four} {one four two} {one two three} {one four} {one two}} sl@0: sl@0: finish_test