fulltext_cursor *c = (fulltext_cursor *) pCursor;
fulltext_vtab *v = cursor_vtab(c);
int rc;
- char *zSql;
TRACE(("FTS2 Filter %p\n",pCursor));
- zSql = sqlite3_mprintf("select rowid, * from %%_content %s",
- idxNum==QUERY_GENERIC ? "" : "where rowid=?");
- sqlite3_finalize(c->pStmt);
- rc = sql_prepare(v->db, v->zDb, v->zName, &c->pStmt, zSql);
- sqlite3_free(zSql);
- if( rc!=SQLITE_OK ) return rc;
+ /* If the cursor has a statement that was not prepared according to
+ ** idxNum, clear it. I believe all calls to fulltextFilter with a
+ ** given cursor will have the same idxNum , but in this case it's
+ ** easy to be safe.
+ */
+ if( c->pStmt && c->iCursorType!=idxNum ){
+ sqlite3_finalize(c->pStmt);
+ c->pStmt = NULL;
+ }
+
+ /* Get a fresh statement appropriate to idxNum. */
+ /* TODO(shess): Add a prepared-statement cache in the vt structure.
+ ** The cache must handle multiple open cursors. Easier to cache the
+ ** statement variants at the vt to reduce malloc/realloc/free here.
+ ** Or we could have a StringBuffer variant which allowed stack
+ ** construction for small values.
+ */
+ if( !c->pStmt ){
+ char *zSql = sqlite3_mprintf("select rowid, * from %%_content %s",
+ idxNum==QUERY_GENERIC ? "" : "where rowid=?");
+ rc = sql_prepare(v->db, v->zDb, v->zName, &c->pStmt, zSql);
+ sqlite3_free(zSql);
+ if( rc!=SQLITE_OK ) return rc;
+ c->iCursorType = idxNum;
+ }else{
+ sqlite3_reset(c->pStmt);
+ assert( c->iCursorType==idxNum );
+ }
- c->iCursorType = idxNum;
switch( idxNum ){
case QUERY_GENERIC:
break;
-C Add\ssome\ssimple\stests\sto\smake\ssure\sthat\sthe\sdifferent\sfulltextFilter\nquery\spaths\sare\sbeing\sexercised.\s(CVS\s5498)
-D 2008-07-29T20:24:46
+C Backport\shttp://www.sqlite.org/cvstrac/chngview?cn=5489\sfrom\sfts3.\nRe-used\sprepared\sstatement\sfrom\sfts2\scursor.\s(CVS\s5499)
+D 2008-07-29T20:38:18
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in bbb62eecc851379aef5a48a1bf8787eb13e6ec06
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F ext/fts1/tokenizer.h 0c53421b832366d20d720d21ea3e1f6e66a36ef9
F ext/fts2/README.tokenizers 21e3684ea5a095b55d70f6878b4ce6af5932dfb7
F ext/fts2/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
-F ext/fts2/fts2.c 5f6f8fa8f756d37a5eb271ea42e56a103f965ef5
+F ext/fts2/fts2.c bc78da57642edfcf7ba2fb8a8771f97663449104
F ext/fts2/fts2.h da5f76c65163301d1068a971fd32f4119e3c95fa
F ext/fts2/fts2_hash.c 2689e42e1107ea67207f725cf69cf8972d00cf93
F ext/fts2/fts2_hash.h 9a5b1be94664139f93217a0770d7144425cffb3a
F test/fts2o.test c6a79567d85403dc4d15b89f3f9799a0a0aef065
F test/fts2p.test 4b48c35c91e6a7dbf5ac8d1e5691823cc999aafb
F test/fts2q.test b2fbbe038b7a31a52a6079b215e71226d8c6a682
+F test/fts2r.test b154c30b63061d8725e320fba1a39e2201cadd5e
F test/fts2token.test d8070b241a15ff13592a9ae4a8b7c171af6f445a
F test/fts3.test efb41507c90f47e8af2a9101d7460cddeb84656b
F test/fts3aa.test 432d1d5c41939bb5405d4d6c80a9ec759b363393
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P c449a95c4f7abd2bfb92bed0e3a9ae874350ce79
-R b698c84f6b41998f7179c968db38e9a8
+P ae96d960e6e31315d25c7e5c3fb8363ed1b35350
+R c8b28180ba8665612880184e0c20b27c
U shess
-Z 8007ccac7fb34b00a3c12fd8cb677718
+Z 55f351b9e5be2316c863f86a07e2dcf1
--- /dev/null
+# 2008 July 29
+#
+# The author disclaims copyright to this source code. In place of
+# a legal notice, here is a blessing:
+#
+# May you do good and not evil.
+# May you find forgiveness for yourself and forgive others.
+# May you share freely, never taking more than you give.
+#
+#*************************************************************************
+# These tests exercise the various types of fts2 cursors.
+#
+# $Id: fts2r.test,v 1.1 2008/07/29 20:38:18 shess Exp $
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# If SQLITE_ENABLE_FTS2 is not defined, omit this file.
+ifcapable !fts2 {
+ finish_test
+ return
+}
+
+#*************************************************************************
+# Test table scan (QUERY_GENERIC). This kind of query happens for
+# queries with no WHERE clause, or for WHERE clauses which cannot be
+# satisfied by an index.
+db eval {
+ DROP TABLE IF EXISTS t1;
+ CREATE VIRTUAL TABLE t1 USING fts2(c);
+ INSERT INTO t1 (rowid, c) VALUES (1, 'This is a test');
+ INSERT INTO t1 (rowid, c) VALUES (2, 'That was a test');
+ INSERT INTO t1 (rowid, c) VALUES (3, 'This is a test');
+}
+
+do_test fts2e-1.1 {
+ execsql {
+ SELECT rowid FROM t1 ORDER BY rowid;
+ }
+} {1 2 3}
+
+do_test fts2e-1.2 {
+ execsql {
+ SELECT rowid FROM t1 WHERE c LIKE '%test' ORDER BY rowid;
+ }
+} {1 2 3}
+
+do_test fts2e-1.3 {
+ execsql {
+ SELECT rowid FROM t1 WHERE c LIKE 'That%' ORDER BY rowid;
+ }
+} {2}
+
+#*************************************************************************
+# Test lookup by rowid (QUERY_ROWID). This kind of query happens for
+# queries which select by the rowid implicit index.
+db eval {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE VIRTUAL TABLE t1 USING fts2(c);
+ CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
+ INSERT INTO t2 VALUES (null, 10);
+ INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
+ INSERT INTO t2 VALUES (null, 5);
+ INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'That was a test');
+ INSERT INTO t2 VALUES (null, 20);
+ INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
+}
+
+# TODO(shess): This actually is doing QUERY_GENERIC? I'd have
+# expected QUERY_ROWID in this case, as for a very large table the
+# full scan is less efficient.
+do_test fts2e-2.1 {
+ execsql {
+ SELECT rowid FROM t1 WHERE rowid in (1, 2, 10);
+ }
+} {1 2}
+
+do_test fts2e-2.2 {
+ execsql {
+ SELECT t1.rowid, weight FROM t1, t2 WHERE t2.id = t1.rowid ORDER BY weight;
+ }
+} {2 5 1 10 3 20}
+
+do_test fts2e-2.3 {
+ execsql {
+ SELECT t1.rowid, weight FROM t1, t2
+ WHERE t2.weight>5 AND t2.id = t1.rowid ORDER BY weight;
+ }
+} {1 10 3 20}
+
+#*************************************************************************
+# Test lookup by MATCH (QUERY_FULLTEXT). This is the fulltext index.
+db eval {
+ DROP TABLE IF EXISTS t1;
+ DROP TABLE IF EXISTS t2;
+ CREATE VIRTUAL TABLE t1 USING fts2(c);
+ CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, weight INTEGER UNIQUE);
+ INSERT INTO t2 VALUES (null, 10);
+ INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
+ INSERT INTO t2 VALUES (null, 5);
+ INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'That was a test');
+ INSERT INTO t2 VALUES (null, 20);
+ INSERT INTO t1 (rowid, c) VALUES (last_insert_rowid(), 'This is a test');
+}
+
+do_test fts2e-3.1 {
+ execsql {
+ SELECT rowid FROM t1 WHERE t1 MATCH 'this' ORDER BY rowid;
+ }
+} {1 3}
+
+do_test fts2e-3.2 {
+ execsql {
+ SELECT t1.rowid, weight FROM t1, t2
+ WHERE t1 MATCH 'this' AND t1.rowid = t2.id ORDER BY weight;
+ }
+} {1 10 3 20}
+
+finish_test