sl@0: # 2007 March 9 sl@0: # sl@0: # The author disclaims copyright to this source code. sl@0: # sl@0: #************************************************************************* sl@0: # This file implements regression tests for SQLite library. These sl@0: # make sure that fts2 insertion buffering is fully transparent when sl@0: # using transactions. sl@0: # sl@0: # $Id: fts2k.test,v 1.2 2007/08/10 23:47:04 shess Exp $ sl@0: # sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: # If SQLITE_ENABLE_FTS2 is defined, omit this file. sl@0: ifcapable !fts2 { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: db eval { sl@0: CREATE VIRTUAL TABLE t1 USING fts2(content); sl@0: INSERT INTO t1 (rowid, content) VALUES(1, "hello world"); sl@0: INSERT INTO t1 (rowid, content) VALUES(2, "hello there"); sl@0: INSERT INTO t1 (rowid, content) VALUES(3, "cruel world"); sl@0: } sl@0: sl@0: # Test that possibly-buffered inserts went through after commit. sl@0: do_test fts2k-1.1 { sl@0: execsql { sl@0: BEGIN TRANSACTION; sl@0: INSERT INTO t1 (rowid, content) VALUES(4, "false world"); sl@0: INSERT INTO t1 (rowid, content) VALUES(5, "false door"); sl@0: COMMIT TRANSACTION; sl@0: SELECT rowid FROM t1 WHERE t1 MATCH 'world'; sl@0: } sl@0: } {1 3 4} sl@0: sl@0: # Test that buffered inserts are seen by selects in the same sl@0: # transaction. sl@0: do_test fts2k-1.2 { sl@0: execsql { sl@0: BEGIN TRANSACTION; sl@0: INSERT INTO t1 (rowid, content) VALUES(6, "another world"); sl@0: INSERT INTO t1 (rowid, content) VALUES(7, "another test"); sl@0: SELECT rowid FROM t1 WHERE t1 MATCH 'world'; sl@0: COMMIT TRANSACTION; sl@0: } sl@0: } {1 3 4 6} sl@0: sl@0: # Test that buffered inserts are seen within a transaction. This is sl@0: # really the same test as 1.2. sl@0: do_test fts2k-1.3 { sl@0: execsql { sl@0: BEGIN TRANSACTION; sl@0: INSERT INTO t1 (rowid, content) VALUES(8, "second world"); sl@0: INSERT INTO t1 (rowid, content) VALUES(9, "second sight"); sl@0: SELECT rowid FROM t1 WHERE t1 MATCH 'world'; sl@0: ROLLBACK TRANSACTION; sl@0: } sl@0: } {1 3 4 6 8} sl@0: sl@0: # Double-check that the previous result doesn't persist past the sl@0: # rollback! sl@0: do_test fts2k-1.4 { sl@0: execsql { sl@0: SELECT rowid FROM t1 WHERE t1 MATCH 'world'; sl@0: } sl@0: } {1 3 4 6} sl@0: sl@0: # Test it all together. sl@0: do_test fts2k-1.5 { sl@0: execsql { sl@0: BEGIN TRANSACTION; sl@0: INSERT INTO t1 (rowid, content) VALUES(10, "second world"); sl@0: INSERT INTO t1 (rowid, content) VALUES(11, "second sight"); sl@0: ROLLBACK TRANSACTION; sl@0: SELECT rowid FROM t1 WHERE t1 MATCH 'world'; sl@0: } sl@0: } {1 3 4 6} sl@0: sl@0: # Test that the obvious case works. sl@0: do_test fts2k-1.6 { sl@0: execsql { sl@0: BEGIN; sl@0: INSERT INTO t1 (rowid, content) VALUES(12, "third world"); sl@0: COMMIT; sl@0: SELECT rowid FROM t1 WHERE t1 MATCH 'third'; sl@0: } sl@0: } {12} sl@0: sl@0: # This is exactly the same as the previous test, except that older sl@0: # code loses the INSERT due to an SQLITE_SCHEMA error. sl@0: do_test fts2k-1.7 { sl@0: execsql { sl@0: BEGIN; sl@0: INSERT INTO t1 (rowid, content) VALUES(13, "third dimension"); sl@0: CREATE TABLE x (c); sl@0: COMMIT; sl@0: SELECT rowid FROM t1 WHERE t1 MATCH 'dimension'; sl@0: } sl@0: } {13} sl@0: sl@0: finish_test