os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fts3b.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/fts3b.test	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,218 @@
     1.4 +# 2007 August 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.  This
    1.15 +# script tests for the fts2 rowid-versus-vacuum problem (ticket #2566).
    1.16 +#
    1.17 +# $Id: fts3b.test,v 1.3 2007/09/13 18:14:49 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 +db eval {
    1.30 +  CREATE VIRTUAL TABLE t1 USING fts3(c);
    1.31 +  INSERT INTO t1 (c) VALUES('this is a test');
    1.32 +  INSERT INTO t1 (c) VALUES('that was a test');
    1.33 +  INSERT INTO t1 (c) VALUES('this is fun');
    1.34 +  DELETE FROM t1 WHERE c = 'that was a test';
    1.35 +}
    1.36 +
    1.37 +# Baseline test.
    1.38 +do_test fts3b-1.1 {
    1.39 +  execsql {
    1.40 +    SELECT rowid FROM t1 WHERE c MATCH 'this';
    1.41 +  }
    1.42 +} {1 3}
    1.43 +
    1.44 +db eval {VACUUM}
    1.45 +
    1.46 +# The VACUUM renumbered the t1_content table in fts2, which breaks
    1.47 +# this.
    1.48 +do_test fts3b-1.2 {
    1.49 +  execsql {
    1.50 +    SELECT rowid FROM t1 WHERE c MATCH 'this';
    1.51 +  }
    1.52 +} {1 3}
    1.53 +
    1.54 +# The t2 table is unfortunately pretty contrived.  We need documents
    1.55 +# that are bigger than ROOT_MAX (1024) to force segments out of the
    1.56 +# segdir and into %_segments.  We also need to force segment merging
    1.57 +# to generate a hole in the %_segments table, which needs more than 16
    1.58 +# docs.  Beyond that, to test correct operation of BLOCK_SELECT_STMT,
    1.59 +# we need to merge a mult-level tree, which is where the 10,000 comes
    1.60 +# from.  Which is slow, thus the set of transactions, with the 500
    1.61 +# being a number such that 10,000/500 > 16.
    1.62 +set text {
    1.63 +  Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas
    1.64 +  iaculis mollis ipsum. Praesent rhoncus placerat justo. Duis non quam
    1.65 +  sed turpis posuere placerat. Curabitur et lorem in lorem porttitor
    1.66 +  aliquet. Pellentesque bibendum tincidunt diam. Vestibulum blandit
    1.67 +  ante nec elit. In sapien diam, facilisis eget, dictum sed, viverra
    1.68 +  at, felis. Vestibulum magna. Sed magna dolor, vestibulum rhoncus,
    1.69 +  ornare vel, vulputate sit amet, felis. Integer malesuada, tellus at
    1.70 +  luctus gravida, diam nunc porta nibh, nec imperdiet massa metus eu
    1.71 +  lectus. Aliquam nisi. Nunc fringilla nulla at lectus. Suspendisse
    1.72 +  potenti. Cum sociis natoque penatibus et magnis dis parturient
    1.73 +  montes, nascetur ridiculus mus. Pellentesque odio nulla, feugiat eu,
    1.74 +  suscipit nec, consequat quis, risus.
    1.75 +}
    1.76 +append text $text
    1.77 +
    1.78 +db eval {CREATE VIRTUAL TABLE t2 USING fts3(c)}
    1.79 +set res {}
    1.80 +db eval {BEGIN}
    1.81 +for {set ii 0} {$ii<10000} {incr ii} {
    1.82 +  db eval {INSERT INTO t2 (c) VALUES ($text)}
    1.83 +  lappend res [expr {$ii+1}]
    1.84 +  if {($ii%500)==0} {
    1.85 +    db eval {
    1.86 +      COMMIT;
    1.87 +      BEGIN;
    1.88 +    }
    1.89 +  }
    1.90 +}
    1.91 +db eval {COMMIT}
    1.92 +
    1.93 +do_test fts3b-2.1 {
    1.94 +  execsql {
    1.95 +    SELECT rowid FROM t2 WHERE c MATCH 'lorem';
    1.96 +  }
    1.97 +} $res
    1.98 +
    1.99 +db eval {VACUUM}
   1.100 +
   1.101 +# The VACUUM renumbered the t2_segment table in fts2, which would
   1.102 +# break the following.
   1.103 +do_test fts3b-2.2 {
   1.104 +  execsql {
   1.105 +    SELECT rowid FROM t2 WHERE c MATCH 'lorem';
   1.106 +  }
   1.107 +} $res
   1.108 +
   1.109 +# Since fts3 is already an API break, I've marked the table-named
   1.110 +# column HIDDEN.
   1.111 +
   1.112 +db eval {
   1.113 +  CREATE VIRTUAL TABLE t3 USING fts3(c);
   1.114 +  INSERT INTO t3 (c) VALUES('this is a test');
   1.115 +  INSERT INTO t3 (c) VALUES('that was a test');
   1.116 +  INSERT INTO t3 (c) VALUES('this is fun');
   1.117 +  DELETE FROM t3 WHERE c = 'that was a test';
   1.118 +}
   1.119 +
   1.120 +# Test that the table-named column still works.
   1.121 +do_test fts3b-3.1 {
   1.122 +  execsql {
   1.123 +    SELECT snippet(t3) FROM t3 WHERE t3 MATCH 'test';
   1.124 +  }
   1.125 +} {{this is a <b>test</b>}}
   1.126 +
   1.127 +# Test that the column doesn't appear when selecting all columns.
   1.128 +do_test fts3b-3.2 {
   1.129 +  execsql {
   1.130 +    SELECT * FROM t3 WHERE rowid = 1;
   1.131 +  }
   1.132 +} {{this is a test}}
   1.133 +
   1.134 +# Test that the column doesn't conflict with inserts that don't name
   1.135 +# columns.
   1.136 +do_test fts3b-3.3 {
   1.137 +  execsql {
   1.138 +    INSERT INTO t3 VALUES ('another test');
   1.139 +  }
   1.140 +} {}
   1.141 +
   1.142 +# fts3 adds a new implicit column, docid, which acts as an alias for
   1.143 +# rowid.
   1.144 +
   1.145 +db eval {
   1.146 +  CREATE VIRTUAL TABLE t4 USING fts3(c);
   1.147 +  INSERT INTO t4 (c) VALUES('this is a test');
   1.148 +  INSERT INTO t4 (c) VALUES('that was a test');
   1.149 +  INSERT INTO t4 (c) VALUES('this is fun');
   1.150 +  DELETE FROM t4 WHERE c = 'that was a test';
   1.151 +}
   1.152 +
   1.153 +# Test that docid is present and identical to rowid.
   1.154 +do_test fts3b-4.1 {
   1.155 +  execsql {
   1.156 +    SELECT rowid FROM t4 WHERE rowid <> docid;
   1.157 +  }
   1.158 +} {}
   1.159 +
   1.160 +# Test that docid is hidden.
   1.161 +do_test fts3b-4.2 {
   1.162 +  execsql {
   1.163 +    SELECT * FROM t4 WHERE rowid = 1;
   1.164 +  }
   1.165 +} {{this is a test}}
   1.166 +
   1.167 +# Test that docid can be selected.
   1.168 +do_test fts3b-4.3 {
   1.169 +  execsql {
   1.170 +    SELECT docid, * FROM t4 WHERE rowid = 1;
   1.171 +  }
   1.172 +} {1 {this is a test}}
   1.173 +
   1.174 +# Test that docid can be used in WHERE.
   1.175 +do_test fts3b-4.4 {
   1.176 +  execsql {
   1.177 +    SELECT docid, * FROM t4 WHERE docid = 1;
   1.178 +  }
   1.179 +} {1 {this is a test}}
   1.180 +
   1.181 +# Test that the column doesn't conflict with inserts that don't name
   1.182 +# columns.  [Yes, this is the same as fts3b-3.3, here just in case the
   1.183 +# goals of that test change.]
   1.184 +do_test fts3b-4.5 {
   1.185 +  execsql {
   1.186 +    INSERT INTO t4 VALUES ('another test');
   1.187 +  }
   1.188 +} {}
   1.189 +
   1.190 +# Test that the docid can be forced on insert.
   1.191 +do_test fts3b-4.6 {
   1.192 +  execsql {
   1.193 +    INSERT INTO t4 (docid, c) VALUES (10, 'yet another test');
   1.194 +    SELECT * FROM t4 WHERE docid = 10;
   1.195 +  }
   1.196 +} {{yet another test}}
   1.197 +
   1.198 +# Test that rowid can also be forced.
   1.199 +do_test fts3b-4.7 {
   1.200 +  execsql {
   1.201 +    INSERT INTO t4 (docid, c) VALUES (12, 'still testing');
   1.202 +    SELECT * FROM t4 WHERE docid = 12;
   1.203 +  }
   1.204 +} {{still testing}}
   1.205 +
   1.206 +# If an insert tries to set both docid and rowid, require an error.
   1.207 +do_test fts3b-4.8 {
   1.208 +  catchsql {
   1.209 +    INSERT INTO t4 (rowid, docid, c) VALUES (14, 15, 'bad test');
   1.210 +    SELECT * FROM t4 WHERE docid = 14;
   1.211 +  }
   1.212 +} {1 {SQL logic error or missing database}}
   1.213 +
   1.214 +# Don't allow update of docid, to match rowid behaviour.
   1.215 +do_test fts3b-4.9 {
   1.216 +  catchsql {
   1.217 +    UPDATE t4 SET docid = 14 WHERE docid = 12;
   1.218 +  }
   1.219 +} {1 {SQL logic error or missing database}}
   1.220 +
   1.221 +finish_test