sl@0: # 2007 June 20 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 sl@0: # focus of this script is testing the FTS3 module. sl@0: # sl@0: # $Id: fts3ao.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 not defined, omit this file. sl@0: ifcapable !fts3 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: #--------------------------------------------------------------------- sl@0: # These tests, fts3ao-1.*, test that ticket #2429 is fixed. sl@0: # sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t1 USING fts3(a, b, c); sl@0: INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two'); sl@0: } sl@0: do_test fts3ao-1.1 { sl@0: execsql { sl@0: SELECT rowid, snippet(t1) FROM t1 WHERE c MATCH 'four'; sl@0: } sl@0: } {1 {one four two}} sl@0: do_test fts3ao-1.2 { sl@0: execsql { sl@0: SELECT rowid, snippet(t1) FROM t1 WHERE b MATCH 'four'; sl@0: } sl@0: } {1 {one four}} sl@0: do_test fts3ao-1.3 { sl@0: execsql { sl@0: SELECT rowid, snippet(t1) FROM t1 WHERE a MATCH 'four'; sl@0: } sl@0: } {1 {one three four}} sl@0: sl@0: #--------------------------------------------------------------------- sl@0: # Test that it is possible to rename an fts3 table. sl@0: # sl@0: do_test fts3ao-2.1 { sl@0: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} sl@0: } {t1 t1_content t1_segments t1_segdir} sl@0: do_test fts3ao-2.2 { sl@0: execsql { ALTER TABLE t1 RENAME to fts_t1; } sl@0: } {} sl@0: do_test fts3ao-2.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 fts3ao-2.4 { sl@0: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} sl@0: } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir} sl@0: sl@0: # See what happens when renaming the fts3 table fails. sl@0: # sl@0: do_test fts3ao-2.5 { sl@0: catchsql { sl@0: CREATE TABLE t1_segdir(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 fts3ao-2.6 { 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 fts3ao-2.7 { sl@0: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} sl@0: } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir} sl@0: sl@0: # See what happens when renaming the fts3 table fails inside a transaction. sl@0: # sl@0: do_test fts3ao-2.8 { 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 fts3ao-2.9 { 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: do_test fts3ao-2.10 { 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 fts3ao-2.11 { sl@0: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'} sl@0: } {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir} sl@0: do_test fts3ao-2.12 { sl@0: execsql COMMIT sl@0: execsql {SELECT a FROM fts_t1} sl@0: } {{one three four} {one two three}} sl@0: do_test fts3ao-2.12 { 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: # Close, delete and reopen the database. The following test should sl@0: # be run on an initially empty db. sl@0: # sl@0: db close sl@0: file delete -force test.db test.db-journal sl@0: sqlite3 db test.db sl@0: sl@0: do_test fts3ao-3.1 { sl@0: execsql { sl@0: CREATE VIRTUAL TABLE t1 USING fts3(a, b, c); sl@0: INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one two'); sl@0: SELECT a, b, c FROM t1 WHERE c MATCH 'two'; sl@0: } sl@0: } {{one three four} {one four} {one two}} sl@0: sl@0: # This test was crashing at one point. sl@0: # sl@0: do_test fts3ao-3.2 { sl@0: execsql { sl@0: SELECT a, b, c FROM t1 WHERE c MATCH 'two'; sl@0: CREATE TABLE t3(a, b, c); sl@0: SELECT a, b, c FROM t1 WHERE c MATCH 'two'; sl@0: } sl@0: } {{one three four} {one four} {one two} {one three four} {one four} {one two}} sl@0: sl@0: #--------------------------------------------------------------------- sl@0: # Test that it is possible to rename an fts3 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 fts3ao-3.1 { sl@0: execsql { sl@0: ATTACH 'test2.db' AS aux; sl@0: CREATE VIRTUAL TABLE aux.t1 USING fts3(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 fts3ao-3.2 { 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 fts3ao-3.3 { sl@0: execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } sl@0: } {{one three four} {one four} {one two}} sl@0: sl@0: do_test fts3ao-3.4 { sl@0: execsql { ALTER TABLE aux.t1 RENAME TO t2 } sl@0: } {} sl@0: sl@0: do_test fts3ao-3.2 { 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 fts3ao-3.3 { sl@0: execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; } sl@0: } {{one three four} {one four} {one two}} sl@0: sl@0: finish_test