os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fts1o.test
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fts1o.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,138 @@
     1.4 +# 2007 July 24
     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 focus
    1.15 +# of this script is testing the FTS1 module rename functionality.  Mostly
    1.16 +# copied from fts2o.test.
    1.17 +#
    1.18 +# $Id: fts1o.test,v 1.2 2007/08/30 20:01:33 shess Exp $
    1.19 +#
    1.20 +
    1.21 +set testdir [file dirname $argv0]
    1.22 +source $testdir/tester.tcl
    1.23 +
    1.24 +# If SQLITE_ENABLE_FTS1 is not defined, omit this file.
    1.25 +ifcapable !fts1 {
    1.26 +  finish_test
    1.27 +  return
    1.28 +}
    1.29 +
    1.30 +db eval {
    1.31 +  CREATE VIRTUAL TABLE t1 USING fts1(a, b, c);
    1.32 +  INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one four two');
    1.33 +}
    1.34 +
    1.35 +#---------------------------------------------------------------------
    1.36 +# Test that it is possible to rename an fts1 table.
    1.37 +#
    1.38 +do_test fts1o-1.1 {
    1.39 +  execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
    1.40 +} {t1 t1_content t1_term}
    1.41 +do_test fts1o-1.2 {
    1.42 +  execsql { ALTER TABLE t1 RENAME to fts_t1; }
    1.43 +} {}
    1.44 +do_test fts1o-1.3 {
    1.45 +  execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
    1.46 +} {1 {one three <b>four</b>}}
    1.47 +do_test fts1o-1.4 {
    1.48 +  execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
    1.49 +} {fts_t1 fts_t1_content fts_t1_term}
    1.50 +
    1.51 +# See what happens when renaming the fts1 table fails.
    1.52 +#
    1.53 +do_test fts1o-2.1 {
    1.54 +  catchsql {
    1.55 +    CREATE TABLE t1_term(a, b, c);
    1.56 +    ALTER TABLE fts_t1 RENAME to t1;
    1.57 +  }
    1.58 +} {1 {SQL logic error or missing database}}
    1.59 +do_test fts1o-2.2 {
    1.60 +  execsql { SELECT rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
    1.61 +} {1 {one three <b>four</b>}}
    1.62 +do_test fts1o-2.3 {
    1.63 +  execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
    1.64 +} {fts_t1 fts_t1_content fts_t1_term t1_term}
    1.65 +
    1.66 +# See what happens when renaming the fts1 table fails inside a transaction.
    1.67 +#
    1.68 +do_test fts1o-3.1 {
    1.69 +  execsql {
    1.70 +    BEGIN;
    1.71 +    INSERT INTO fts_t1(a, b, c) VALUES('one two three', 'one four', 'one two');
    1.72 +  }
    1.73 +} {}
    1.74 +do_test fts1o-3.2 {
    1.75 +  catchsql {
    1.76 +    ALTER TABLE fts_t1 RENAME to t1;
    1.77 +  }
    1.78 +} {1 {SQL logic error or missing database}}
    1.79 +# NOTE(shess) rowid AS rowid to defeat caching.  Otherwise, this
    1.80 +# seg-faults, I suspect that there's something up with a stale
    1.81 +# virtual-table reference, but I'm not quite sure how it happens here
    1.82 +# but not for fts2o.test.
    1.83 +do_test fts1o-3.3 {
    1.84 +  execsql { SELECT rowid AS rowid, snippet(fts_t1) FROM fts_t1 WHERE a MATCH 'four'; }
    1.85 +} {1 {one three <b>four</b>}}
    1.86 +do_test fts1o-3.4 {
    1.87 +  execsql { SELECT tbl_name FROM sqlite_master WHERE type = 'table'}
    1.88 +} {fts_t1 fts_t1_content fts_t1_term t1_term}
    1.89 +do_test fts1o-3.5 {
    1.90 +  execsql COMMIT
    1.91 +  execsql {SELECT a FROM fts_t1}
    1.92 +} {{one three four} {one two three}}
    1.93 +do_test fts1o-3.6 {
    1.94 +  execsql { SELECT a, b, c FROM fts_t1 WHERE c MATCH 'four'; }
    1.95 +} {{one three four} {one four} {one four two}}
    1.96 +
    1.97 +#---------------------------------------------------------------------
    1.98 +# Test that it is possible to rename an fts1 table in an attached 
    1.99 +# database.
   1.100 +#
   1.101 +file delete -force test2.db test2.db-journal
   1.102 +
   1.103 +do_test fts1o-4.1 {
   1.104 +  execsql {
   1.105 +    DROP TABLE t1_term;
   1.106 +    ALTER TABLE fts_t1 RENAME to t1;
   1.107 +    SELECT a, b, c FROM t1 WHERE c MATCH 'two';
   1.108 +  }
   1.109 +} {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
   1.110 +
   1.111 +do_test fts1o-4.2 {
   1.112 +  execsql {
   1.113 +    ATTACH 'test2.db' AS aux;
   1.114 +    CREATE VIRTUAL TABLE aux.t1 USING fts1(a, b, c);
   1.115 +    INSERT INTO aux.t1(a, b, c) VALUES(
   1.116 +      'neung song sahm', 'neung see', 'neung see song'
   1.117 +    );
   1.118 +  }
   1.119 +} {}
   1.120 +
   1.121 +do_test fts1o-4.3 {
   1.122 +  execsql { SELECT a, b, c FROM aux.t1 WHERE a MATCH 'song'; }
   1.123 +} {{neung song sahm} {neung see} {neung see song}}
   1.124 +
   1.125 +do_test fts1o-4.4 {
   1.126 +  execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
   1.127 +} {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
   1.128 +
   1.129 +do_test fts1o-4.5 {
   1.130 +  execsql { ALTER TABLE aux.t1 RENAME TO t2 }
   1.131 +} {}
   1.132 +
   1.133 +do_test fts1o-4.6 {
   1.134 +  execsql { SELECT a, b, c FROM t2 WHERE a MATCH 'song'; }
   1.135 +} {{neung song sahm} {neung see} {neung see song}}
   1.136 +
   1.137 +do_test fts1o-4.7 {
   1.138 +  execsql { SELECT a, b, c FROM t1 WHERE c MATCH 'two'; }
   1.139 +} {{one three four} {one four} {one four two} {one two three} {one four} {one two}}
   1.140 +
   1.141 +finish_test