1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/persistentdata/persistentstorage/sqlite3api/TEST/TclScript/fts2k.test Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,105 @@
1.4 +# 2007 March 9
1.5 +#
1.6 +# The author disclaims copyright to this source code.
1.7 +#
1.8 +#*************************************************************************
1.9 +# This file implements regression tests for SQLite library. These
1.10 +# make sure that fts2 insertion buffering is fully transparent when
1.11 +# using transactions.
1.12 +#
1.13 +# $Id: fts2k.test,v 1.2 2007/08/10 23:47:04 shess Exp $
1.14 +#
1.15 +
1.16 +set testdir [file dirname $argv0]
1.17 +source $testdir/tester.tcl
1.18 +
1.19 +# If SQLITE_ENABLE_FTS2 is defined, omit this file.
1.20 +ifcapable !fts2 {
1.21 + finish_test
1.22 + return
1.23 +}
1.24 +
1.25 +db eval {
1.26 + CREATE VIRTUAL TABLE t1 USING fts2(content);
1.27 + INSERT INTO t1 (rowid, content) VALUES(1, "hello world");
1.28 + INSERT INTO t1 (rowid, content) VALUES(2, "hello there");
1.29 + INSERT INTO t1 (rowid, content) VALUES(3, "cruel world");
1.30 +}
1.31 +
1.32 +# Test that possibly-buffered inserts went through after commit.
1.33 +do_test fts2k-1.1 {
1.34 + execsql {
1.35 + BEGIN TRANSACTION;
1.36 + INSERT INTO t1 (rowid, content) VALUES(4, "false world");
1.37 + INSERT INTO t1 (rowid, content) VALUES(5, "false door");
1.38 + COMMIT TRANSACTION;
1.39 + SELECT rowid FROM t1 WHERE t1 MATCH 'world';
1.40 + }
1.41 +} {1 3 4}
1.42 +
1.43 +# Test that buffered inserts are seen by selects in the same
1.44 +# transaction.
1.45 +do_test fts2k-1.2 {
1.46 + execsql {
1.47 + BEGIN TRANSACTION;
1.48 + INSERT INTO t1 (rowid, content) VALUES(6, "another world");
1.49 + INSERT INTO t1 (rowid, content) VALUES(7, "another test");
1.50 + SELECT rowid FROM t1 WHERE t1 MATCH 'world';
1.51 + COMMIT TRANSACTION;
1.52 + }
1.53 +} {1 3 4 6}
1.54 +
1.55 +# Test that buffered inserts are seen within a transaction. This is
1.56 +# really the same test as 1.2.
1.57 +do_test fts2k-1.3 {
1.58 + execsql {
1.59 + BEGIN TRANSACTION;
1.60 + INSERT INTO t1 (rowid, content) VALUES(8, "second world");
1.61 + INSERT INTO t1 (rowid, content) VALUES(9, "second sight");
1.62 + SELECT rowid FROM t1 WHERE t1 MATCH 'world';
1.63 + ROLLBACK TRANSACTION;
1.64 + }
1.65 +} {1 3 4 6 8}
1.66 +
1.67 +# Double-check that the previous result doesn't persist past the
1.68 +# rollback!
1.69 +do_test fts2k-1.4 {
1.70 + execsql {
1.71 + SELECT rowid FROM t1 WHERE t1 MATCH 'world';
1.72 + }
1.73 +} {1 3 4 6}
1.74 +
1.75 +# Test it all together.
1.76 +do_test fts2k-1.5 {
1.77 + execsql {
1.78 + BEGIN TRANSACTION;
1.79 + INSERT INTO t1 (rowid, content) VALUES(10, "second world");
1.80 + INSERT INTO t1 (rowid, content) VALUES(11, "second sight");
1.81 + ROLLBACK TRANSACTION;
1.82 + SELECT rowid FROM t1 WHERE t1 MATCH 'world';
1.83 + }
1.84 +} {1 3 4 6}
1.85 +
1.86 +# Test that the obvious case works.
1.87 +do_test fts2k-1.6 {
1.88 + execsql {
1.89 + BEGIN;
1.90 + INSERT INTO t1 (rowid, content) VALUES(12, "third world");
1.91 + COMMIT;
1.92 + SELECT rowid FROM t1 WHERE t1 MATCH 'third';
1.93 + }
1.94 +} {12}
1.95 +
1.96 +# This is exactly the same as the previous test, except that older
1.97 +# code loses the INSERT due to an SQLITE_SCHEMA error.
1.98 +do_test fts2k-1.7 {
1.99 + execsql {
1.100 + BEGIN;
1.101 + INSERT INTO t1 (rowid, content) VALUES(13, "third dimension");
1.102 + CREATE TABLE x (c);
1.103 + COMMIT;
1.104 + SELECT rowid FROM t1 WHERE t1 MATCH 'dimension';
1.105 + }
1.106 +} {13}
1.107 +
1.108 +finish_test