Backport http://www.sqlite.org/cvstrac/chngview?cn=5489 from fts3.
Re-used prepared statement from fts2 cursor. (CVS 5499) FossilOrigin-Name: 02870ed21dae2601a656b2f30c3ca0041e9cb60f
This commit is contained in:
+28
-8
@@ -3777,18 +3777,38 @@ static int fulltextFilter(
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user