/ Check-in [fc918f7d]
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:Fix CSV import issue, reported via the mailing list, in the shell when the file to be imported ends with an empty line.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fc918f7d332b8f7cabc79a0f1586bd6760d14d40
User & Date: mistachkin 2014-06-16 22:45:28
Context
2014-06-17
15:53
Improvements to query planning, especially in regards to estimating the cost and benefit of automatic indexes. check-in: 1272fb89 user: drh tags: trunk
02:46
Do not attempt to create an automatic index on a constant constraint, as doing so is pointless. check-in: d6883e96 user: drh tags: autoindex-improvements
2014-06-16
22:45
Fix CSV import issue, reported via the mailing list, in the shell when the file to be imported ends with an empty line. check-in: fc918f7d user: mistachkin tags: trunk
21:30
In the "wheretrace" logic (disabled for normal builds) expand the print width of the flags field to be wide enough for all 17 bits. check-in: 3181d206 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/shell.c.

2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
        if( z==0 && i==0 ) break;
        sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
        if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
          fprintf(stderr, "%s:%d: expected %d columns but found %d - "
                          "filling the rest with NULL\n",
                          sCsv.zFile, startLine, nCol, i+1);
          i++;
          while( i<nCol ){ sqlite3_bind_null(pStmt, i); i++; }
        }
      }
      if( sCsv.cTerm==sCsv.cSeparator ){
        do{
          csv_read_one_field(&sCsv);
          i++;
        }while( sCsv.cTerm==sCsv.cSeparator );







|







2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
        if( z==0 && i==0 ) break;
        sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
        if( i<nCol-1 && sCsv.cTerm!=sCsv.cSeparator ){
          fprintf(stderr, "%s:%d: expected %d columns but found %d - "
                          "filling the rest with NULL\n",
                          sCsv.zFile, startLine, nCol, i+1);
          i++;
          while( i<=nCol ){ sqlite3_bind_null(pStmt, i); i++; }
        }
      }
      if( sCsv.cTerm==sCsv.cSeparator ){
        do{
          csv_read_one_field(&sCsv);
          i++;
        }while( sCsv.cTerm==sCsv.cSeparator );

Changes to test/shell5.test.

352
353
354
355
356
357
358












359
360
361
.mode csv
CREATE TABLE t4(a, b);
.import shell5.csv t4
  }]
  db eval { SELECT * FROM t4 }
} {xy\" hello}















finish_test







>
>
>
>
>
>
>
>
>
>
>
>



352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
.mode csv
CREATE TABLE t4(a, b);
.import shell5.csv t4
  }]
  db eval { SELECT * FROM t4 }
} {xy\" hello}

do_test shell5-2.5 {
  set fd [open shell5.csv w]
  puts $fd {"one","2"}
  puts $fd {}
  close $fd
  catchcmd test.db [string trim {
.mode csv
CREATE TABLE t4(a, b);
.import shell5.csv t4
  }]
  db eval { SELECT * FROM t4 }
} {xy\" hello one 2 {} {}}


finish_test