1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fts3ao.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,169 @@
1.4 +# 2007 June 20
1.5 +#
1.6 +# The author disclaims copyright to this source code. In place of
1.7 +# a legal notice, here is a blessing:
1.8 +#
1.9 +# May you do good and not evil.
1.10 +# May you find forgiveness for yourself and forgive others.
1.11 +# May you share freely, never taking more than you give.
1.12 +#
1.13 +#*************************************************************************
1.14 +# This file implements regression tests for SQLite library. The
1.15 +# focus of this script is testing the FTS3 module.
1.16 +#
1.17 +# $Id: fts3ao.test,v 1.1 2007/08/20 17:38:42 shess Exp $
1.18 +#
1.19 +
1.20 +set testdir [file dirname $argv0]
1.21 +source $testdir/tester.tcl
1.22 +
1.23 +# If SQLITE_ENABLE_FTS3 is not defined, omit this file.
1.24 +ifcapable !fts3 {
1.25 + finish_test
1.26 + return
1.27 +}
1.28 +
1.29 +#---------------------------------------------------------------------
1.30 +# These tests, fts3ao-1.*, test that ticket #2429 is fixed.
1.31 +#
1.32 +db eval {
1.33 + CREATE VIRTUAL TABLE t1 USING fts3(a, b, c);
1.34 + INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two');
1.35 +}
1.36 +do_test fts3ao-1.1 {
1.37 + execsql {
1.38 + SELECT rowid, snippet(t1) FROM t1 WHERE c MATCH 'four';
1.39 + }
1.40 +} {1 {one <b>four</b> two}}
1.41 +do_test fts3ao-1.2 {
1.42 + execsql {
1.43 + SELECT rowid, snippet(t1) FROM t1 WHERE b MATCH 'four';
1.44 + }
1.45 +} {1 {one <b>four</b>}}
1.46 +do_test fts3ao-1.3 {
1.47 + execsql {
1.48 + SELECT rowid, snippet(t1) FROM t1 WHERE a MATCH 'four';
1.49 + }
1.50 +} {1 {one three <b>four</b>}}
1.51 +
1.52 +#---------------------------------------------------------------------
1.53 +# Test that it is possible to rename an fts3 table.
1.54 +#
1.55 +do_test fts3ao-2.1 {
1.56 + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
1.57 +} {t1 t1_content t1_segments t1_segdir}
1.58 +do_test fts3ao-2.2 {
1.59 + execsql { ALTER TABLE t1 RENAME to fts_t1; }
1.60 +} {}
1.61 +do_test fts3ao-2.3 {
1.62 + execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
1.63 +} {1 {one three <b>four</b>}}
1.64 +do_test fts3ao-2.4 {
1.65 + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
1.66 +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir}
1.67 +
1.68 +# See what happens when renaming the fts3 table fails.
1.69 +#
1.70 +do_test fts3ao-2.5 {
1.71 + catchsql {
1.72 + CREATE TABLE t1_segdir(a, b, c);
1.73 + ALTER TABLE fts_t1 RENAME to t1;
1.74 + }
1.75 +} {1 {SQL logic error or missing database}}
1.76 +do_test fts3ao-2.6 {
1.77 + execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
1.78 +} {1 {one three <b>four</b>}}
1.79 +do_test fts3ao-2.7 {
1.80 + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
1.81 +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir}
1.82 +
1.83 +# See what happens when renaming the fts3 table fails inside a transaction.
1.84 +#
1.85 +do_test fts3ao-2.8 {
1.86 + execsql {
1.87 + BEGIN;
1.88 + INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two');
1.89 + }
1.90 +} {}
1.91 +do_test fts3ao-2.9 {
1.92 + catchsql {
1.93 + ALTER TABLE fts_t1 RENAME to t1;
1.94 + }
1.95 +} {1 {SQL logic error or missing database}}
1.96 +do_test fts3ao-2.10 {
1.97 + execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
1.98 +} {1 {one three <b>four</b>}}
1.99 +do_test fts3ao-2.11 {
1.100 + execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
1.101 +} {fts_t1 fts_t1_content fts_t1_segments fts_t1_segdir t1_segdir}
1.102 +do_test fts3ao-2.12 {
1.103 + execsql COMMIT
1.104 + execsql {SELECT a FROM fts_t1}
1.105 +} {{one three four} {one two three}}
1.106 +do_test fts3ao-2.12 {
1.107 + execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; }
1.108 +} {{one three four} {one four} {one four two}}
1.109 +
1.110 +#-------------------------------------------------------------------
1.111 +# Close, delete and reopen the database. The following test should
1.112 +# be run on an initially empty db.
1.113 +#
1.114 +db close
1.115 +file delete -force test.db test.db-journal
1.116 +sqlite3 db test.db
1.117 +
1.118 +do_test fts3ao-3.1 {
1.119 + execsql {
1.120 + CREATE VIRTUAL TABLE t1 USING fts3(a, b, c);
1.121 + INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one two');
1.122 + SELECT a, b, c FROM t1 WHERE c MATCH 'two';
1.123 + }
1.124 +} {{one three four} {one four} {one two}}
1.125 +
1.126 +# This test was crashing at one point.
1.127 +#
1.128 +do_test fts3ao-3.2 {
1.129 + execsql {
1.130 + SELECT a, b, c FROM t1 WHERE c MATCH 'two';
1.131 + CREATE TABLE t3(a, b, c);
1.132 + SELECT a, b, c FROM t1 WHERE c MATCH 'two';
1.133 + }
1.134 +} {{one three four} {one four} {one two} {one three four} {one four} {one two}}
1.135 +
1.136 +#---------------------------------------------------------------------
1.137 +# Test that it is possible to rename an fts3 table in an attached
1.138 +# database.
1.139 +#
1.140 +file delete -force test2.db test2.db-journal
1.141 +
1.142 +do_test fts3ao-3.1 {
1.143 + execsql {
1.144 + ATTACH 'test2.db' AS aux;
1.145 + CREATE VIRTUAL TABLE aux.t1 USING fts3(a, b, c);
1.146 + INSERT INTO aux.t1(a, b, c) VALUES(
1.147 + 'neung song sahm', 'neung see', 'neung see song'
1.148 + );
1.149 + }
1.150 +} {}
1.151 +
1.152 +do_test fts3ao-3.2 {
1.153 + execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; }
1.154 +} {{neung song sahm} {neung see} {neung see song}}
1.155 +
1.156 +do_test fts3ao-3.3 {
1.157 + execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
1.158 +} {{one three four} {one four} {one two}}
1.159 +
1.160 +do_test fts3ao-3.4 {
1.161 + execsql { ALTER TABLE aux.t1 RENAME TO t2 }
1.162 +} {}
1.163 +
1.164 +do_test fts3ao-3.2 {
1.165 + execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; }
1.166 +} {{neung song sahm} {neung see} {neung see song}}
1.167 +
1.168 +do_test fts3ao-3.3 {
1.169 + execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
1.170 +} {{one three four} {one four} {one two}}
1.171 +
1.172 +finish_test