Annotation of embedaddon/sqlite3/test/fts1o.test, revision 1.1
1.1 ! misho 1: # 2007 July 24
! 2: #
! 3: # The author disclaims copyright to this source code. In place of
! 4: # a legal notice, here is a blessing:
! 5: #
! 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.
! 9: #
! 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.
! 14: #
! 15: # $Id: fts1o.test,v 1.2 2007/08/30 20:01:33 shess Exp $
! 16: #
! 17:
! 18: set testdir [file dirname $argv0]
! 19: source $testdir/tester.tcl
! 20:
! 21: # If SQLITE_ENABLE_FTS1 is not defined, omit this file.
! 22: ifcapable !fts1 {
! 23: finish_test
! 24: return
! 25: }
! 26:
! 27: db eval {
! 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');
! 30: }
! 31:
! 32: #---------------------------------------------------------------------
! 33: # Test that it is possible to rename an fts1 table.
! 34: #
! 35: do_test fts1o-1.1 {
! 36: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
! 37: } {t1 t1_content t1_term}
! 38: do_test fts1o-1.2 {
! 39: execsql { ALTER TABLE t1 RENAME to fts_t1; }
! 40: } {}
! 41: do_test fts1o-1.3 {
! 42: execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
! 43: } {1 {one three <b>four</b>}}
! 44: do_test fts1o-1.4 {
! 45: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
! 46: } {fts_t1 fts_t1_content fts_t1_term}
! 47:
! 48: # See what happens when renaming the fts1 table fails.
! 49: #
! 50: do_test fts1o-2.1 {
! 51: catchsql {
! 52: CREATE TABLE t1_term(a, b, c);
! 53: ALTER TABLE fts_t1 RENAME to t1;
! 54: }
! 55: } {1 {SQL logic error or missing database}}
! 56: do_test fts1o-2.2 {
! 57: execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
! 58: } {1 {one three <b>four</b>}}
! 59: do_test fts1o-2.3 {
! 60: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
! 61: } {fts_t1 fts_t1_content fts_t1_term t1_term}
! 62:
! 63: # See what happens when renaming the fts1 table fails inside a transaction.
! 64: #
! 65: do_test fts1o-3.1 {
! 66: execsql {
! 67: BEGIN;
! 68: INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two');
! 69: }
! 70: } {}
! 71: do_test fts1o-3.2 {
! 72: catchsql {
! 73: ALTER TABLE fts_t1 RENAME to t1;
! 74: }
! 75: } {1 {SQL logic error or missing database}}
! 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.
! 80: do_test fts1o-3.3 {
! 81: execsql { SELECT rowid AS rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
! 82: } {1 {one three <b>four</b>}}
! 83: do_test fts1o-3.4 {
! 84: execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
! 85: } {fts_t1 fts_t1_content fts_t1_term t1_term}
! 86: do_test fts1o-3.5 {
! 87: execsql COMMIT
! 88: execsql {SELECT a FROM fts_t1}
! 89: } {{one three four} {one two three}}
! 90: do_test fts1o-3.6 {
! 91: execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; }
! 92: } {{one three four} {one four} {one four two}}
! 93:
! 94: #---------------------------------------------------------------------
! 95: # Test that it is possible to rename an fts1 table in an attached
! 96: # database.
! 97: #
! 98: forcedelete test2.db test2.db-journal
! 99:
! 100: do_test fts1o-4.1 {
! 101: execsql {
! 102: DROP TABLE t1_term;
! 103: ALTER TABLE fts_t1 RENAME to t1;
! 104: SELECT a, b, c FROM t1 WHERE c MATCH 'two';
! 105: }
! 106: } {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
! 107:
! 108: do_test fts1o-4.2 {
! 109: execsql {
! 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'
! 114: );
! 115: }
! 116: } {}
! 117:
! 118: do_test fts1o-4.3 {
! 119: execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; }
! 120: } {{neung song sahm} {neung see} {neung see song}}
! 121:
! 122: do_test fts1o-4.4 {
! 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}}
! 125:
! 126: do_test fts1o-4.5 {
! 127: execsql { ALTER TABLE aux.t1 RENAME TO t2 }
! 128: } {}
! 129:
! 130: do_test fts1o-4.6 {
! 131: execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; }
! 132: } {{neung song sahm} {neung see} {neung see song}}
! 133:
! 134: do_test fts1o-4.7 {
! 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}}
! 137:
! 138: finish_test
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>