From: dan Date: Fri, 8 May 2015 09:21:05 +0000 (+0000) Subject: Improve the error message returned by FTS5 if it encounters an unknown file format. X-Git-Tag: version-3.8.11~114^2~48 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=76724372ae254b8381fcac659c7a386c8ae80922;p=thirdparty%2Fsqlite.git Improve the error message returned by FTS5 if it encounters an unknown file format. FossilOrigin-Name: f369caec145f311bb136cf7af144e2695badcb9b --- diff --git a/ext/fts5/fts5.c b/ext/fts5/fts5.c index df1646786a..cd4eff325d 100644 --- a/ext/fts5/fts5.c +++ b/ext/fts5/fts5.c @@ -943,6 +943,10 @@ static int fts5FilterMethod( Fts5Cursor *pCsr = (Fts5Cursor*)pCursor; int bDesc = ((idxNum & FTS5_ORDER_DESC) ? 1 : 0); int rc = SQLITE_OK; + char **pzErrmsg = pTab->pConfig->pzErrmsg; + + assert( pzErrmsg==0 || pzErrmsg==&pTab->base.zErrMsg ); + pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg; assert( nVal<=2 ); assert( pCsr->pStmt==0 ); @@ -1004,6 +1008,7 @@ static int fts5FilterMethod( } } + pTab->pConfig->pzErrmsg = pzErrmsg; return rc; } @@ -1205,6 +1210,9 @@ static int fts5UpdateMethod( /* A transaction must be open when this is called. */ assert( pTab->ts.eState==1 ); + assert( pTab->pConfig->pzErrmsg==0 ); + pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg; + /* A delete specifies a single argument - the rowid of the row to remove. ** Update and insert operations pass: ** @@ -1241,10 +1249,11 @@ static int fts5UpdateMethod( if( pConfig->eContent!=FTS5_CONTENT_NORMAL && 0==sqlite3_stricmp("delete", z) ){ - return fts5SpecialDelete(pTab, apVal, pRowid); + rc = fts5SpecialDelete(pTab, apVal, pRowid); }else{ - return fts5SpecialInsert(pTab, pCmd, apVal[2 + pConfig->nCol + 1]); + rc = fts5SpecialInsert(pTab, pCmd, apVal[2 + pConfig->nCol + 1]); } + goto update_method_out; } } @@ -1253,6 +1262,8 @@ static int fts5UpdateMethod( rc = sqlite3Fts5StorageInsert(pTab->pStorage, apVal, eConflict, pRowid); } + update_method_out: + pTab->pConfig->pzErrmsg = 0; return rc; } @@ -1263,8 +1274,10 @@ static int fts5SyncMethod(sqlite3_vtab *pVtab){ int rc; Fts5Table *pTab = (Fts5Table*)pVtab; fts5CheckTransactionState(pTab, FTS5_SYNC, 0); + pTab->pConfig->pzErrmsg = &pTab->base.zErrMsg; fts5TripCursors(pTab); rc = sqlite3Fts5StorageSync(pTab->pStorage, 1); + pTab->pConfig->pzErrmsg = 0; return rc; } diff --git a/ext/fts5/fts5Int.h b/ext/fts5/fts5Int.h index d09029710b..696a8ea5a7 100644 --- a/ext/fts5/fts5Int.h +++ b/ext/fts5/fts5Int.h @@ -96,6 +96,11 @@ typedef struct Fts5Config Fts5Config; ** ** zContentExprlist: ** +** pzErrmsg: +** This exists in order to allow the fts5_index.c module to return a +** decent error message if it encounters a file-format version it does +** not understand. +** */ struct Fts5Config { sqlite3 *db; /* Database handle */ @@ -120,6 +125,9 @@ struct Fts5Config { int nCrisisMerge; /* Maximum allowed segments per level */ char *zRank; /* Name of rank function */ char *zRankArgs; /* Arguments to rank function */ + + /* If non-NULL, points to sqlite3_vtab.base.zErrmsg. Often NULL. */ + char **pzErrmsg; }; /* Current expected value of %_config table 'version' field */ diff --git a/ext/fts5/fts5_config.c b/ext/fts5/fts5_config.c index 0846eec8f6..90d7b7318f 100644 --- a/ext/fts5/fts5_config.c +++ b/ext/fts5/fts5_config.c @@ -851,7 +851,14 @@ int sqlite3Fts5ConfigLoad(Fts5Config *pConfig, int iCookie){ } if( rc==SQLITE_OK && iVersion!=FTS5_CURRENT_VERSION ){ - rc = sqlite3Fts5Corrupt(); + rc = SQLITE_ERROR; + if( pConfig->pzErrmsg ){ + assert( 0==*pConfig->pzErrmsg ); + *pConfig->pzErrmsg = sqlite3_mprintf( + "invalid fts5 file format (found %d, expected %d) - run 'rebuild'", + iVersion, FTS5_CURRENT_VERSION + ); + } } if( rc==SQLITE_OK ){ diff --git a/ext/fts5/test/fts5version.test b/ext/fts5/test/fts5version.test new file mode 100644 index 0000000000..4e5df579e5 --- /dev/null +++ b/ext/fts5/test/fts5version.test @@ -0,0 +1,59 @@ +# 2015 Apr 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. +# +#*********************************************************************** +# +# The tests in this file focus on testing that unrecognized file-format +# versions are detected and reported. +# + +source [file join [file dirname [info script]] fts5_common.tcl] +set testprefix fts5version + + +do_execsql_test 1.1 { + CREATE VIRTUAL TABLE t1 USING fts5(one); + INSERT INTO t1 VALUES('a b c d'); +} {} + +do_execsql_test 1.2 { + SELECT * FROM t1_config WHERE k='version' +} {version 1} + +do_execsql_test 1.3 { + SELECT rowid FROM t1 WHERE t1 MATCH 'a'; +} {1} + +do_execsql_test 1.4 { + UPDATE t1_config set v=2 WHERE k='version'; +} + +do_test 1.5 { + db close + sqlite3 db test.db + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' } +} {1 {invalid fts5 file format (found 2, expected 1) - run 'rebuild'}} + +breakpoint +do_test 1.6 { + db close + sqlite3 db test.db + catchsql { INSERT INTO t1 VALUES('x y z') } +} {1 {invalid fts5 file format (found 2, expected 1) - run 'rebuild'}} + +do_test 1.7 { + execsql { DELETE FROM t1_config WHERE k='version' } + db close + sqlite3 db test.db + catchsql { SELECT * FROM t1 WHERE t1 MATCH 'a' } +} {1 {invalid fts5 file format (found 0, expected 1) - run 'rebuild'}} + + +finish_test + diff --git a/manifest b/manifest index c9a1dfd035..76b5dac082 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sto\sstoring\sall\skeys\sin\sa\ssingle\smerge-tree\sstructure\sinstead\sof\sone\smain\sstructure\sand\sa\sseparate\sone\sfor\seach\sprefix\sindex.\sThis\sis\sa\sfile-format\schange.\sAlso\sintroduce\sa\smechanism\sfor\smanaging\sfile-format\schanges. -D 2015-05-07T19:29:46.763 +C Improve\sthe\serror\smessage\sreturned\sby\sFTS5\sif\sit\sencounters\san\sunknown\sfile\sformat. +D 2015-05-08T09:21:05.416 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 31b38b9da2e4b36f54a013bd71a5c3f6e45ca78f F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -104,12 +104,12 @@ F ext/fts3/unicode/CaseFolding.txt 8c678ca52ecc95e16bc7afc2dbf6fc9ffa05db8c F ext/fts3/unicode/UnicodeData.txt cd07314edb62d49fde34debdaf92fa2aa69011e7 F ext/fts3/unicode/mkunicode.tcl 159c1194da0bc72f51b3c2eb71022568006dc5ad F ext/fts5/extract_api_docs.tcl 55a6d648d516f35d9a1e580ac00de27154e1904a -F ext/fts5/fts5.c 62b2657320aac309d7bcf2bfb855f8d4c216ae15 +F ext/fts5/fts5.c 7f58ea9ba1e72038137963719c5b5335f499cecd F ext/fts5/fts5.h 24a2cc35b5e76eec57b37ba48c12d9d2cb522b3a -F ext/fts5/fts5Int.h 94b1800ea50e52ce19365744174c65e6fc8b87e0 +F ext/fts5/fts5Int.h be8ac04ce40705aa088c3d2509cadad0f98085fa F ext/fts5/fts5_aux.c d53f00f31ad615ca4f139dd8751f9041afa00971 F ext/fts5/fts5_buffer.c 70b971e13503566f1e257941c60817ba0920a16b -F ext/fts5/fts5_config.c 7a8b4665239a4f3001a4ecbc77573c42d2694161 +F ext/fts5/fts5_config.c 05811f0bd80c396afcf3ceea68da16149a9a3258 F ext/fts5/fts5_expr.c 3fe1170453d6a322d2de8a3fd0aed3edff7b8b09 F ext/fts5/fts5_hash.c 54dd25348a46ea62ea96322c572e08cd1fb37304 F ext/fts5/fts5_index.c aa8d73d043417740c07861beb78c86103a6a9d90 @@ -163,6 +163,7 @@ F ext/fts5/test/fts5tokenizer.test bbcde2a7473dcaa9a1fc6809aa8965acb7b846ff F ext/fts5/test/fts5unicode.test 79b3e34eb29ce4929628aa514a40cb467fdabe4d F ext/fts5/test/fts5unicode2.test 64a5267fd6082fcb46439892ebd0cbaa5c38acee F ext/fts5/test/fts5unindexed.test f388605341a476b6ab622b4c267cd168f59a5944 +F ext/fts5/test/fts5version.test 1c902eaa7359336293ac45c7a34616527513e9fb F ext/fts5/tool/loadfts5.tcl 8a8f10d7d2d0d77f622e0a84cc0824c158c34a52 F ext/fts5/tool/showfts5.tcl 921f33b30c3189deefd2b2cc81f951638544aaf1 F ext/icu/README.txt d9fbbad0c2f647c3fdf715fc9fd64af53aedfc43 @@ -1316,7 +1317,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P c4456dc5f5f8f45f04e3bbae53b6bcc209fc27d5 -R d535b9198036ecff3827ebadb9a9b6f4 +P a684b5e2d9d52cf4700e7e5f9dd547a2ba54e8e9 +R ee87a64da50ec14a005ebb86ec227c20 U dan -Z 02d7c47a9ec4004e437813912cd05f33 +Z 8aaf7ae5929104d0a1ed12733f883e2b diff --git a/manifest.uuid b/manifest.uuid index d0b2967a0c..9406775af2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a684b5e2d9d52cf4700e7e5f9dd547a2ba54e8e9 \ No newline at end of file +f369caec145f311bb136cf7af144e2695badcb9b \ No newline at end of file