/ Check-in [95f483e8]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the CSV extension to the test fixture. Fix a memory leak in the CSV extension. Add test cases for the CSV extension, including one that uses a WITHOUT ROWID virtual table participating in the OR optimization.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | without-rowid-vtab
Files: files | file ages | folders
SHA1: 95f483e86e30ae68108904400e18ed41d389446b
User & Date: drh 2016-06-02 23:13:21
Context
2016-06-03
01:01
Performance optimizations on the CSV virtual table. Disallow WITHOUT ROWID virtual tables that have an xUpdate method, for now. check-in: 3134b326 user: drh tags: without-rowid-vtab
2016-06-02
23:13
Add the CSV extension to the test fixture. Fix a memory leak in the CSV extension. Add test cases for the CSV extension, including one that uses a WITHOUT ROWID virtual table participating in the OR optimization. check-in: 95f483e8 user: drh tags: without-rowid-vtab
17:44
Add the data= parameter to the CSV virtual table extension. check-in: 76919104 user: drh tags: without-rowid-vtab
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Makefile.in.

   413    413     $(TOP)/ext/rbu/test_rbu.c 
   414    414   
   415    415   # Statically linked extensions
   416    416   #
   417    417   TESTSRC += \
   418    418     $(TOP)/ext/misc/amatch.c \
   419    419     $(TOP)/ext/misc/closure.c \
          420  +  $(TOP)/ext/misc/csv.c \
   420    421     $(TOP)/ext/misc/eval.c \
   421    422     $(TOP)/ext/misc/fileio.c \
   422    423     $(TOP)/ext/misc/fuzzer.c \
   423    424     $(TOP)/ext/fts5/fts5_tcl.c \
   424    425     $(TOP)/ext/fts5/fts5_test_mi.c \
   425    426     $(TOP)/ext/fts5/fts5_test_tok.c \
   426    427     $(TOP)/ext/misc/ieee754.c \

Changes to Makefile.msc.

  1289   1289     $(TOP)\ext\session\test_session.c
  1290   1290   
  1291   1291   # Statically linked extensions.
  1292   1292   #
  1293   1293   TESTEXT = \
  1294   1294     $(TOP)\ext\misc\amatch.c \
  1295   1295     $(TOP)\ext\misc\closure.c \
         1296  +  $(TOP)\ext\misc\csv.c \
  1296   1297     $(TOP)\ext\misc\eval.c \
  1297   1298     $(TOP)\ext\misc\fileio.c \
  1298   1299     $(TOP)\ext\misc\fuzzer.c \
  1299   1300     $(TOP)\ext\fts5\fts5_tcl.c \
  1300   1301     $(TOP)\ext\fts5\fts5_test_mi.c \
  1301   1302     $(TOP)\ext\fts5\fts5_test_tok.c \
  1302   1303     $(TOP)\ext\misc\ieee754.c \

Changes to ext/misc/csv.c.

   298    298   
   299    299   /*
   300    300   ** This method is the destructor fo a CsvTable object.
   301    301   */
   302    302   static int csvtabDisconnect(sqlite3_vtab *pVtab){
   303    303     CsvTable *p = (CsvTable*)pVtab;
   304    304     sqlite3_free(p->zFilename);
          305  +  sqlite3_free(p->zData);
   305    306     sqlite3_free(p);
   306    307     return SQLITE_OK;
   307    308   }
   308    309   
   309    310   /* Skip leading whitespace.  Return a pointer to the first non-whitespace
   310    311   ** character, or to the zero terminator if the string has only whitespace */
   311    312   static const char *csv_skip_whitespace(const char *z){

Changes to main.mk.

   321    321     $(TOP)/src/test_wsd.c
   322    322   
   323    323   # Extensions to be statically loaded.
   324    324   #
   325    325   TESTSRC += \
   326    326     $(TOP)/ext/misc/amatch.c \
   327    327     $(TOP)/ext/misc/closure.c \
          328  +  $(TOP)/ext/misc/csv.c \
   328    329     $(TOP)/ext/misc/eval.c \
   329    330     $(TOP)/ext/misc/fileio.c \
   330    331     $(TOP)/ext/misc/fuzzer.c \
   331    332     $(TOP)/ext/misc/ieee754.c \
   332    333     $(TOP)/ext/misc/nextchar.c \
   333    334     $(TOP)/ext/misc/percentile.c \
   334    335     $(TOP)/ext/misc/regexp.c \

Changes to src/expr.c.

  2531   2531     int regOut      /* Extract the value into this register */
  2532   2532   ){
  2533   2533     if( iCol<0 || iCol==pTab->iPKey ){
  2534   2534       sqlite3VdbeAddOp2(v, OP_Rowid, iTabCur, regOut);
  2535   2535     }else{
  2536   2536       int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
  2537   2537       int x = iCol;
  2538         -    if( !HasRowid(pTab) ){
         2538  +    if( !HasRowid(pTab) && !IsVirtual(pTab) ){
  2539   2539         x = sqlite3ColumnOfIndex(sqlite3PrimaryKeyIndex(pTab), iCol);
  2540   2540       }
  2541   2541       sqlite3VdbeAddOp3(v, op, iTabCur, x, regOut);
  2542   2542     }
  2543   2543     if( iCol>=0 ){
  2544   2544       sqlite3ColumnDefault(v, pTab, iCol, regOut);
  2545   2545     }

Changes to src/test1.c.

  6580   6580     void * clientData,
  6581   6581     Tcl_Interp *interp,
  6582   6582     int objc,
  6583   6583     Tcl_Obj *CONST objv[]
  6584   6584   ){
  6585   6585     extern int sqlite3_amatch_init(sqlite3*,char**,const sqlite3_api_routines*);
  6586   6586     extern int sqlite3_closure_init(sqlite3*,char**,const sqlite3_api_routines*);
         6587  +  extern int sqlite3_csv_init(sqlite3*,char**,const sqlite3_api_routines*);
  6587   6588     extern int sqlite3_eval_init(sqlite3*,char**,const sqlite3_api_routines*);
  6588   6589     extern int sqlite3_fileio_init(sqlite3*,char**,const sqlite3_api_routines*);
  6589   6590     extern int sqlite3_fuzzer_init(sqlite3*,char**,const sqlite3_api_routines*);
  6590   6591     extern int sqlite3_ieee_init(sqlite3*,char**,const sqlite3_api_routines*);
  6591   6592     extern int sqlite3_nextchar_init(sqlite3*,char**,const sqlite3_api_routines*);
  6592   6593     extern int sqlite3_percentile_init(sqlite3*,char**,const sqlite3_api_routines*);
  6593   6594     extern int sqlite3_regexp_init(sqlite3*,char**,const sqlite3_api_routines*);
................................................................................
  6597   6598     extern int sqlite3_wholenumber_init(sqlite3*,char**,const sqlite3_api_routines*);
  6598   6599     static const struct {
  6599   6600       const char *zExtName;
  6600   6601       int (*pInit)(sqlite3*,char**,const sqlite3_api_routines*);
  6601   6602     } aExtension[] = {
  6602   6603       { "amatch",                sqlite3_amatch_init               },
  6603   6604       { "closure",               sqlite3_closure_init              },
         6605  +    { "csv",                   sqlite3_csv_init                  },
  6604   6606       { "eval",                  sqlite3_eval_init                 },
  6605   6607       { "fileio",                sqlite3_fileio_init               },
  6606   6608       { "fuzzer",                sqlite3_fuzzer_init               },
  6607   6609       { "ieee754",               sqlite3_ieee_init                 },
  6608   6610       { "nextchar",              sqlite3_nextchar_init             },
  6609   6611       { "percentile",            sqlite3_percentile_init           },
  6610   6612       { "regexp",                sqlite3_regexp_init               },

Added test/csv01.test.

            1  +# 2016-06-02
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# 
           12  +# Test cases for CSV virtual table.
           13  +
           14  +set testdir [file dirname $argv0]
           15  +source $testdir/tester.tcl
           16  +set testprefix closure01
           17  +
           18  +ifcapable !vtab||!cte { finish_test ; return }
           19  +
           20  +load_static_extension db csv
           21  +
           22  +do_execsql_test 1.0 {
           23  +  CREATE VIRTUAL TABLE temp.t1 USING csv(
           24  +    data=
           25  +'1,2,3,4
           26  +5,6,7,8
           27  +9,10,11,12
           28  +13,14,15,16
           29  +',
           30  +    columns=4
           31  +  );
           32  +  SELECT * FROM t1 WHERE c1=10;
           33  +} {9 10 11 12}
           34  +do_execsql_test 1.1 {
           35  +  SELECT * FROM t1 WHERE c1='10';
           36  +} {9 10 11 12}
           37  +do_execsql_test 1.2 {
           38  +  SELECT rowid FROM t1;
           39  +} {1 2 3 4}
           40  +
           41  +do_execsql_test 2.0 {
           42  +  DROP TABLE t1;
           43  +  CREATE VIRTUAL TABLE temp.t2 USING csv(
           44  +    data=
           45  +'1,2,3,4
           46  +5,6,7,8
           47  +9,10,11,12
           48  +13,14,15,16
           49  +',
           50  +    columns=4,
           51  +    schema='CREATE TABLE t2(a INT, b TEXT, c REAL, d BLOB)'
           52  +  );
           53  +  SELECT * FROM t2 WHERE a=9;
           54  +} {9 10 11 12}
           55  +do_execsql_test 2.1 {
           56  +  SELECT * FROM t2 WHERE b=10;
           57  +} {9 10 11 12}
           58  +do_execsql_test 2.2 {
           59  +  SELECT * FROM t2 WHERE c=11;
           60  +} {9 10 11 12}
           61  +do_execsql_test 2.3 {
           62  +  SELECT * FROM t2 WHERE d=12;
           63  +} {}
           64  +do_execsql_test 2.4 {
           65  +  SELECT * FROM t2 WHERE d='12';
           66  +} {9 10 11 12}
           67  +do_execsql_test 2.5 {
           68  +  SELECT * FROM t2 WHERE a='9';
           69  +} {9 10 11 12}
           70  +
           71  +do_execsql_test 3.0 {
           72  +  DROP TABLE t2;
           73  +  CREATE VIRTUAL TABLE temp.t3 USING csv(
           74  +    data=
           75  +'1,2,3,4
           76  +5,6,7,8
           77  +9,10,11,12
           78  +13,14,15,16
           79  +',
           80  +    columns=4,
           81  +    schema=
           82  +      'CREATE TABLE t3(a PRIMARY KEY,b TEXT,c TEXT,d TEXT) WITHOUT ROWID',
           83  +    testflags=1
           84  +  );
           85  +  SELECT a FROM t3 WHERE b=6 OR c=7 OR d=12 ORDER BY +a;
           86  +} {5 9}
           87  +do_execsql_test 3.1 {
           88  +  SELECT a FROM t3 WHERE +b=6 OR c=7 OR d=12 ORDER BY +a;
           89  +} {5 9}
           90  +
           91  +finish_test