/ Check-in [fc918f7d]
Login

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 Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

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

Changes to test/shell5.test.

   352    352   .mode csv
   353    353   CREATE TABLE t4(a, b);
   354    354   .import shell5.csv t4
   355    355     }]
   356    356     db eval { SELECT * FROM t4 }
   357    357   } {xy\" hello}
   358    358   
          359  +do_test shell5-2.5 {
          360  +  set fd [open shell5.csv w]
          361  +  puts $fd {"one","2"}
          362  +  puts $fd {}
          363  +  close $fd
          364  +  catchcmd test.db [string trim {
          365  +.mode csv
          366  +CREATE TABLE t4(a, b);
          367  +.import shell5.csv t4
          368  +  }]
          369  +  db eval { SELECT * FROM t4 }
          370  +} {xy\" hello one 2 {} {}}
   359    371   
   360    372   
   361    373   finish_test