From 443ecd036d786952de732d609ce94b328a07eb39 Mon Sep 17 00:00:00 2001 From: shess Date: Wed, 25 Jul 2007 00:38:05 +0000 Subject: [PATCH] Replicates http://www.sqlite.org/cvstrac/chngview?cn=4151 which modified fts2: Modify handling of SQLITE_SCHEMA in fts2 code. An SQLITE_SCHEMA error may cause SQLite to reload the internal schema, deleting and recreating v-table objects. So the sqlite3_vtab structure can be deleted out from under a v-table implementation. (CVS 4183) FossilOrigin-Name: f9020cffda02923ef45979bb447ec2e232086ad5 --- ext/fts1/fts1.c | 23 ++++++++--------------- manifest | 13 +++++++------ manifest.uuid | 2 +- test/fts1n.test | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 test/fts1n.test diff --git a/ext/fts1/fts1.c b/ext/fts1/fts1.c index 61b79ea71a..3a4c210719 100644 --- a/ext/fts1/fts1.c +++ b/ext/fts1/fts1.c @@ -1193,25 +1193,18 @@ static int sql_step_statement(fulltext_vtab *v, fulltext_statement iStmt, assert( s==v->pFulltextStatements[iStmt] ); while( (rc=sqlite3_step(s))!=SQLITE_DONE && rc!=SQLITE_ROW ){ - sqlite3_stmt *pNewStmt; - if( rc==SQLITE_BUSY ) continue; if( rc!=SQLITE_ERROR ) return rc; - rc = sqlite3_reset(s); - if( rc!=SQLITE_SCHEMA ) return SQLITE_ERROR; - - v->pFulltextStatements[iStmt] = NULL; /* Still in s */ - rc = sql_get_statement(v, iStmt, &pNewStmt); - if( rc!=SQLITE_OK ) goto err; - *ppStmt = pNewStmt; - - rc = sqlite3_transfer_bindings(s, pNewStmt); - if( rc!=SQLITE_OK ) goto err; - + /* If an SQLITE_SCHEMA error has occured, then finalizing this + * statement is going to delete the fulltext_vtab structure. If + * the statement just executed is in the pFulltextStatements[] + * array, it will be finalized twice. So remove it before + * calling sqlite3_finalize(). + */ + v->pFulltextStatements[iStmt] = NULL; rc = sqlite3_finalize(s); - if( rc!=SQLITE_OK ) return rc; - s = pNewStmt; + break; } return rc; diff --git a/manifest b/manifest index 3237543dd5..d9fd69c85a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Sorry,\sprevious\scheck-in\sincluded\sa\slast-minute\s"Did\sit\sreally\swork?"\nchange\s:-).\s(CVS\s4182) -D 2007-07-25T00:28:00 +C Replicates\shttp://www.sqlite.org/cvstrac/chngview?cn=4151\swhich\nmodified\sfts2:\n\nModify\shandling\sof\sSQLITE_SCHEMA\sin\sfts2\scode.\sAn\sSQLITE_SCHEMA\serror\nmay\scause\sSQLite\sto\sreload\sthe\sinternal\sschema,\sdeleting\sand\nrecreating\sv-table\sobjects.\sSo\sthe\ssqlite3_vtab\sstructure\scan\sbe\ndeleted\sout\sfrom\sunder\sa\sv-table\simplementation.\s(CVS\s4183) +D 2007-07-25T00:38:06 F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -24,7 +24,7 @@ F ext/README.txt 913a7bd3f4837ab14d7e063304181787658b14e1 F ext/fts1/README.txt 20ac73b006a70bcfd80069bdaf59214b6cf1db5e F ext/fts1/ft_hash.c 3927bd880e65329bdc6f506555b228b28924921b F ext/fts1/ft_hash.h 1a35e654a235c2c662d3ca0dfc3138ad60b8b7d5 -F ext/fts1/fts1.c f9294f39e16f3b853922820751b35b7d6cd25a03 +F ext/fts1/fts1.c 61fa4154f754f79f044c9534d0f52505050b57cc F ext/fts1/fts1.h 6060b8f62c1d925ea8356cb1a6598073eb9159a6 F ext/fts1/fts1_hash.c 3196cee866edbebb1c0521e21672e6d599965114 F ext/fts1/fts1_hash.h 957d378355ed29f672cd5add012ce8b088a5e089 @@ -243,6 +243,7 @@ F test/fts1j.test e4c0ffcd0ba2adce09c6b7b43ffd0749b5fda5c7 F test/fts1k.test fdf295cb797ba6a2ef81ec41cb98df0ceb2e572c F test/fts1l.test 15c119ed2362b2b28d5300c0540a6a43eab66c36 F test/fts1m.test 2d9ca67b095d49f037a914087cc0a61e89da4f0c +F test/fts1n.test a2317dcd27b1d087ee3878b30e0a59c593c98b7a F test/fts1porter.test d86e9c3e0c7f8ff95add6582b4b585fb4e02b96d F test/fts2a.test 473a5c8b473a4e21a8e3fddaed1e59666e0c6ab7 F test/fts2b.test 964abc0236c849c07ca1ae496bb25c268ae94816 @@ -521,7 +522,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P c2ba3cc0f7ac9f5dfe5ffb554f9a1cd96b28335a -R e83da9b483b1007864d54e3b9b822ce1 +P 5db25e369a1a4b5a4d87947abdbf25f96fe64807 +R 4f3383b3dfe35035aa76c90af94680b3 U shess -Z a1ea838168f8478a43be68f2abc4d644 +Z f88d97eea6886d33f533493eb19a7860 diff --git a/manifest.uuid b/manifest.uuid index 91d79489b5..7d385f7388 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -5db25e369a1a4b5a4d87947abdbf25f96fe64807 \ No newline at end of file +f9020cffda02923ef45979bb447ec2e232086ad5 \ No newline at end of file diff --git a/test/fts1n.test b/test/fts1n.test new file mode 100644 index 0000000000..2f102b4e2c --- /dev/null +++ b/test/fts1n.test @@ -0,0 +1,45 @@ +# 2007 July 24 +# +# 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. +# +#************************************************************************* +# This file implements regression tests for SQLite library. The focus +# of this script is testing the FTS1 module for errors in the handling +# of SQLITE_SCHEMA. +# +# $Id: fts1n.test,v 1.1 2007/07/25 00:38:06 shess Exp $ +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +# If SQLITE_ENABLE_FTS1 is not defined, omit this file. +ifcapable !fts1 { + finish_test + return +} + +do_test fts1m-1.1 { + execsql { + CREATE VIRTUAL TABLE t1 USING fts1(a, b, c); + INSERT INTO t1(a, b, c) VALUES('one three four', 'one four', 'one two'); + SELECT a, b, c FROM t1 WHERE c MATCH 'two'; + } +} {{one three four} {one four} {one two}} + +# This test was crashing at one point. +# +do_test fts1m-1.2 { + execsql { + SELECT a, b, c FROM t1 WHERE c MATCH 'two'; + CREATE TABLE t3(a, b, c); + SELECT a, b, c FROM t1 WHERE c MATCH 'two'; + } +} {{one three four} {one four} {one two} {one three four} {one four} {one two}} + +finish_test