Add the testflags parameter to the csv extension.

FossilOrigin-Name: b93fb2fe0df1b3bea2bc2a4e1528da74ab290593
This commit is contained in:
drh 2016-05-31 18:08:35 +00:00
parent 724b18966d
commit abfd272b59
3 changed files with 35 additions and 8 deletions

View File

@ -218,8 +218,12 @@ typedef struct CsvTable {
char *zFilename; /* Name of the CSV file */
long iStart; /* Offset to start of data in zFilename */
int nCol; /* Number of columns in the CSV file */
unsigned int tstFlags; /* Bit values used for testing */
} CsvTable;
/* Allowed values for tstFlags */
#define CSVTEST_FIDX 0x0001 /* Pretend that constrained searchs cost less*/
/* A cursor for the CSV virtual table */
typedef struct CsvCursor {
sqlite3_vtab_cursor base; /* Base class. Must be first */
@ -314,6 +318,7 @@ static int csv_boolean(const char *z){
** schema=SCHEMA Optional
** header=YES|NO First row of CSV defines the names of
** columns if "yes". Default "no".
** testflags=N Bitmask of test flags. Optional
**
** If header=no and not columns are listed, then the columns are named
** "c0", "c1", "c2", and so forth.
@ -331,6 +336,7 @@ static int csvtabConnect(
int i;
char *zFilename = 0;
char *zSchema = 0;
int tstFlags = 0;
CsvReader sRdr;
memset(&sRdr, 0, sizeof(sRdr));
@ -373,6 +379,9 @@ static int csvtabConnect(
goto csvtab_connect_error;
}
}else
if( (zValue = csv_parameter("testflags",9,z))!=0 ){
tstFlags = (unsigned int)atoi(zValue);
}else
{
csv_errmsg(&sRdr, "unrecognized parameter '%s'", z);
goto csvtab_connect_error;
@ -395,6 +404,7 @@ static int csvtabConnect(
pNew->nCol++;
}while( sRdr.cTerm==',' );
pNew->zFilename = zFilename;
pNew->tstFlags = tstFlags;
zFilename = 0;
pNew->iStart = bHeader==1 ? ftell(sRdr.in) : 0;
csv_reader_reset(&sRdr);
@ -426,6 +436,7 @@ csvtab_connect_error:
*pzErr = sqlite3_mprintf("%s", sRdr.zErr);
}
csv_reader_reset(&sRdr);
if( rc==SQLITE_OK ) rc = SQLITE_ERROR;
return rc;
}
@ -571,12 +582,28 @@ static int csvtabFilter(
}
/*
** Only a forwards full table scan is supported. xBestIndex is a no-op.
** Only a forwards full table scan is supported. xBestIndex is mostly
** a no-op. If CSVTEST_FIDX is set, then the presence of equality
** constraints lowers the estimated cost, which is fiction, but is useful
** for testing certain kinds of virtual table behavior.
*/
static int csvtabBestIndex(
sqlite3_vtab *tab,
sqlite3_index_info *pIdxInfo
){
CsvTable *pTab = (CsvTable*)tab;
int i;
pIdxInfo->estimatedCost = 1000000;
if( (pTab->tstFlags & CSVTEST_FIDX)==0 ){
return SQLITE_OK;
}
for(i=0; i<pIdxInfo->nConstraint; i++){
if( pIdxInfo->aConstraint[i].usable==0 ) continue;
if( pIdxInfo->aConstraint[i].op==SQLITE_INDEX_CONSTRAINT_EQ ){
pIdxInfo->estimatedCost = 10;
break;
}
}
return SQLITE_OK;
}

View File

@ -1,5 +1,5 @@
C Add\sthe\s"csv"\svirtual\stable\sfor\sreading\sCSV\sfiles,\sas\san\sextension\sin\nthe\sext/misc/\ssubfolder.
D 2016-05-31T16:22:48.849
C Add\sthe\stestflags\sparameter\sto\sthe\scsv\sextension.
D 2016-05-31T18:08:35.263
F Makefile.in f59e0763ff448719fc1bd25513882b0567286317
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 306d73e854b1a92ea06e5d1e637faa5c44de53c7
@ -206,7 +206,7 @@ F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
F ext/misc/amatch.c 211108e201105e4bb0c076527b8cfd34330fc234
F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704
F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83
F ext/misc/csv.c 386ea82a7eeac9850000b43913a20453bc816a70
F ext/misc/csv.c d9b1dac6e43891174560abdd7d1d68bac20a2277
F ext/misc/eval.c f971962e92ebb8b0a4e6b62949463ee454d88fa2
F ext/misc/fileio.c d4171c815d6543a9edef8308aab2951413cd8d0f
F ext/misc/fuzzer.c 7c64b8197bb77b7d64eff7cac7848870235d4c25
@ -1497,7 +1497,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 64ca1a835a89fd211078d2cd8f9b649e89be528d
R b775d969691f2ff7971a8ef71faf9f8c
P 00d3570c8bb96469c984903e20de589e998d4636
R 7c1772dc60b41e0b51f7bd702d450189
U drh
Z 58655b63021cdf0ee9fb657659454c01
Z ed250383d88d82f9f9e7a2529e3cc23c

View File

@ -1 +1 @@
00d3570c8bb96469c984903e20de589e998d4636
b93fb2fe0df1b3bea2bc2a4e1528da74ab290593