]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add the testflags parameter to the csv extension.
authordrh <drh@noemail.net>
Tue, 31 May 2016 18:08:35 +0000 (18:08 +0000)
committerdrh <drh@noemail.net>
Tue, 31 May 2016 18:08:35 +0000 (18:08 +0000)
FossilOrigin-Name: b93fb2fe0df1b3bea2bc2a4e1528da74ab290593

ext/misc/csv.c
manifest
manifest.uuid

index 62521d81f780a692805dc1f23c3d629ccbd1ec06..d8087664fa8326a9c5cdb847c17488990b0a3c93 100644 (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;
 }
 
index e2d03ea381eee5549cf0342c12a496217251f60f..6ea00aab63764b4f7c7cf6538bc0750a1fd222d8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -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
index 649908c68d6a081175df70857a4cb676c0eaaf89..52e6a805d633ed2b7eacd497247f9d7a91ddf6e7 100644 (file)
@@ -1 +1 @@
-00d3570c8bb96469c984903e20de589e998d4636
\ No newline at end of file
+b93fb2fe0df1b3bea2bc2a4e1528da74ab290593
\ No newline at end of file