Clean up the code for processing FTS4 options a bit.

FossilOrigin-Name: 0425138a2365d23b07d88fda2b1f458f112f389d
This commit is contained in:
dan 2011-06-06 06:55:38 +00:00
parent 76e04431ef
commit 9aab071780
4 changed files with 70 additions and 62 deletions

View File

@ -909,30 +909,12 @@ static int fts3InitVtab(
struct Fts3Index *aIndex; /* Array of indexes for this table */
struct Fts3Index *aFree = 0; /* Free this before returning */
/* The results of parsing supported FTS4 key=value options: */
int bNoDocsize = 0; /* True to omit %_docsize table */
int bDescIdx = 0; /* True to store descending indexes */
char *zMatchinfo = 0; /* Prefix parameter value (or NULL) */
char *zPrefix = 0; /* Prefix parameter value (or NULL) */
char *zCompress = 0; /* compress=? parameter (or NULL) */
char *zUncompress = 0; /* uncompress=? parameter (or NULL) */
char *zOrder = 0; /* order=? parameter (or NULL) */
struct Fts4Option {
const char *zOpt;
int nOpt;
char **pzVar;
} aFts4Opt[] = {
{ "matchinfo", 9, 0 },
{ "prefix", 6, 0 },
{ "compress", 8, 0 },
{ "uncompress", 10, 0 },
{ "order", 5, 0 }
};
aFts4Opt[0].pzVar = &zMatchinfo;
aFts4Opt[1].pzVar = &zPrefix;
aFts4Opt[2].pzVar = &zCompress;
aFts4Opt[3].pzVar = &zUncompress;
aFts4Opt[4].pzVar = &zOrder;
assert( strlen(argv[0])==4 );
assert( (sqlite3_strnicmp(argv[0], "fts4", 4)==0 && isFts4)
@ -973,26 +955,71 @@ static int fts3InitVtab(
/* Check if it is an FTS4 special argument. */
else if( isFts4 && fts3IsSpecialColumn(z, &nKey, &zVal) ){
struct Fts4Option {
const char *zOpt;
int nOpt;
char **pzVar;
} aFts4Opt[] = {
{ "matchinfo", 9, 0 }, /* 0 -> MATCHINFO */
{ "prefix", 6, 0 }, /* 1 -> PREFIX */
{ "compress", 8, 0 }, /* 2 -> COMPRESS */
{ "uncompress", 10, 0 }, /* 3 -> UNCOMPRESS */
{ "order", 5, 0 } /* 4 -> ORDER */
};
int iOpt;
if( !zVal ){
rc = SQLITE_NOMEM;
}else{
for(iOpt=0; iOpt<SizeofArray(aFts4Opt); iOpt++){
if( nKey==aFts4Opt[iOpt].nOpt
&& !sqlite3_strnicmp(z, aFts4Opt[iOpt].zOpt, aFts4Opt[iOpt].nOpt)
){
char **pzVar = aFts4Opt[iOpt].pzVar;
sqlite3_free(*pzVar);
*pzVar = zVal;
zVal = 0;
struct Fts4Option *pOp = &aFts4Opt[iOpt];
if( nKey==pOp->nOpt && !sqlite3_strnicmp(z, pOp->zOpt, pOp->nOpt) ){
break;
}
}
if( zVal ){
if( iOpt==SizeofArray(aFts4Opt) ){
*pzErr = sqlite3_mprintf("unrecognized parameter: %s", z);
rc = SQLITE_ERROR;
sqlite3_free(zVal);
}else{
switch( iOpt ){
case 0: /* MATCHINFO */
if( strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "fts3", 4) ){
*pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zVal);
rc = SQLITE_ERROR;
}
bNoDocsize = 1;
break;
case 1: /* PREFIX */
sqlite3_free(zPrefix);
zPrefix = zVal;
zVal = 0;
break;
case 2: /* COMPRESS */
sqlite3_free(zCompress);
zCompress = zVal;
zVal = 0;
break;
case 3: /* UNCOMPRESS */
sqlite3_free(zUncompress);
zUncompress = zVal;
zVal = 0;
break;
case 4: /* ORDER */
if( (strlen(zVal)!=3 || sqlite3_strnicmp(zVal, "asc", 3))
&& (strlen(zVal)!=4 || sqlite3_strnicmp(zVal, "desc", 3))
){
*pzErr = sqlite3_mprintf("unrecognized order: %s", zVal);
rc = SQLITE_ERROR;
}
bDescIdx = (zVal[0]=='d' || zVal[0]=='D');
break;
}
}
sqlite3_free(zVal);
}
}
@ -1011,26 +1038,6 @@ static int fts3InitVtab(
nCol = 1;
}
if( zMatchinfo ){
if( strlen(zMatchinfo)!=4 || sqlite3_strnicmp(zMatchinfo, "fts3", 4) ){
*pzErr = sqlite3_mprintf("unrecognized matchinfo: %s", zMatchinfo);
rc = SQLITE_ERROR;
goto fts3_init_out;
}
bNoDocsize = 1;
}
if( zOrder ){
if( (strlen(zOrder)!=3 || sqlite3_strnicmp(zOrder, "asc", 3))
&& (strlen(zOrder)!=4 || sqlite3_strnicmp(zOrder, "desc", 3))
){
*pzErr = sqlite3_mprintf("unrecognized order: %s", zOrder);
rc = SQLITE_ERROR;
goto fts3_init_out;
}
bDescIdx = (zOrder[0]=='d' || zOrder[0]=='D');
}
if( pTokenizer==0 ){
rc = sqlite3Fts3InitTokenizer(pHash, "simple", &pTokenizer, pzErr);
if( rc!=SQLITE_OK ) goto fts3_init_out;
@ -1042,8 +1049,7 @@ static int fts3InitVtab(
assert( zPrefix );
*pzErr = sqlite3_mprintf("error parsing prefix parameter: %s", zPrefix);
}
if( rc ) goto fts3_init_out;
if( rc!=SQLITE_OK ) goto fts3_init_out;
/* Allocate and populate the Fts3Table structure. */
nByte = sizeof(Fts3Table) + /* Fts3Table */
@ -1130,8 +1136,6 @@ fts3_init_out:
sqlite3_free(aFree);
sqlite3_free(zCompress);
sqlite3_free(zUncompress);
sqlite3_free(zOrder);
sqlite3_free(zMatchinfo);
sqlite3_free((void *)aCol);
if( rc!=SQLITE_OK ){
if( p ){
@ -4187,7 +4191,10 @@ char *sqlite3Fts3EvalPhrasePoslist(
/*
** Free all components of the Fts3Phrase structure that were allocated by
** the eval module.
** the eval module. Specifically, this means to free:
**
** * the contents of pPhrase->doclist, and
** * any Fts3MultiSegReader objects held by phrase tokens.
*/
void sqlite3Fts3EvalPhraseCleanup(Fts3Phrase *pPhrase){
if( pPhrase ){

View File

@ -1,5 +1,5 @@
C Remove\ssome\sunreachable\scode.
D 2011-06-04T20:13:24.690
C Clean\sup\sthe\scode\sfor\sprocessing\sFTS4\soptions\sa\sbit.
D 2011-06-06T06:55:38.365
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 11dcc00a8d0e5202def00e81732784fb0cc4fe1d
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -61,7 +61,7 @@ F ext/fts2/mkfts2amal.tcl 974d5d438cb3f7c4a652639262f82418c1e4cff0
F ext/fts3/README.syntax a19711dc5458c20734b8e485e75fb1981ec2427a
F ext/fts3/README.tokenizers 998756696647400de63d5ba60e9655036cb966e9
F ext/fts3/README.txt 8c18f41574404623b76917b9da66fcb0ab38328d
F ext/fts3/fts3.c 31f73cae1d21daba547c471a0a78d31e7516a29e
F ext/fts3/fts3.c ea03065c8fbffc7258777fd9e1bf1c40404ce14a
F ext/fts3/fts3.h 3a10a0af180d502cecc50df77b1b22df142817fe
F ext/fts3/fts3Int.h d76b021d5b7061eff7aa4055b5938eebef2bdb6a
F ext/fts3/fts3_aux.c 28fc512608e147015c36080025456f57f571f76f
@ -478,7 +478,7 @@ F test/fts3query.test ef79d31fdb355d094baec1c1b24b60439a1fb8a2
F test/fts3rnd.test 2b1a579be557ab8ac54a51b39caa4aa8043cc4ad
F test/fts3shared.test 8bb266521d7c5495c0ae522bb4d376ad5387d4a2
F test/fts3snippet.test a12f22a3ba4dd59751a57c79b031d07ab5f51ddd
F test/fts3sort.test c599f19e9452b5735c41889ea5a6da996f0ebc7c
F test/fts3sort.test 63d52c1812904b751f9e1ff487472e44833f5402
F test/fts4aa.test eadf85621c0a113d4c7ad3ccbf8441130e007b8f
F test/func.test 6c5ce11e3a0021ca3c0649234e2d4454c89110ca
F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
@ -939,7 +939,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P f6a0193f5a32603eb48bddc6297042dbd2ffe96e
R a65937620eeff7552523045d1ea22bb7
P 650e1a79eda5a2134a1fbd305ab1f205a57c0892
R d2808d37d9a0cf28002d639dd1fa255c
U dan
Z 582e1f65a0e245127649a23c8e5f1248
Z 406d2ac578f3de4e57d0cc24bb1a90c8

View File

@ -1 +1 @@
650e1a79eda5a2134a1fbd305ab1f205a57c0892
0425138a2365d23b07d88fda2b1f458f112f389d

View File

@ -136,7 +136,8 @@ foreach {tn param res} {
1 "order=asc" {0 {}}
2 "order=desc" {0 {}}
3 "order=dec" {1 {unrecognized order: dec}}
4 "order=xxx, order=asc" {0 {}}
4 "order=xxx, order=asc" {1 {unrecognized order: xxx}}
5 "order=desc, order=asc" {0 {}}
} {
execsql { DROP TABLE IF EXISTS t1 }
do_catchsql_test 2.1.$tn "