/ Check-in [856d44a2]
Login

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

Overview
Comment:Fix a problem in the shell when importing CSV files. If the leftmost field of the first row in the CSV file was both zero bytes in size and unquoted, no data was imported.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 856d44a206d82e96265103556dedda39ca3602b1
User & Date: dan 2014-05-26 18:27:12
Context
2014-05-26
22:05
Add the OR-optimization to WITHOUT ROWID tables. check-in: 06a23b8b user: drh tags: trunk
20:15
Merge recent trunk changes into the threads branch. check-in: 82152027 user: drh tags: threads
20:08
Merge recent trunk changes into the apple-osx branch. check-in: 54b5fa77 user: drh tags: apple-osx
20:06
Enable the OR optimization for WITHOUT ROWID tables. Use a temp table instead of the RowSet object to track the rows that have already been included in the result set. check-in: 2c7e277b user: dan tags: without-rowid-or-opt
20:00
Merge recent trunk changes into the sessions branch. check-in: a769c7e0 user: drh tags: sessions
18:27
Fix a problem in the shell when importing CSV files. If the leftmost field of the first row in the CSV file was both zero bytes in size and unquoted, no data was imported. check-in: 856d44a2 user: dan tags: trunk
16:40
Fix a problem in FTS4 where columns with names that are prefixes of any notindexed column were also being (incorrectly) marked as not indexed. For example in "CREATE ... t1(abc, bc, abcd, notindexed=abcd)", both abc and abcd were being treated as notindexed. check-in: d90c4964 user: dan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/shell.c.

2427
2428
2429
2430
2431
2432
2433

2434
2435
2436
2437
2438
2439
2440
    if( zSql==0 ){
      fprintf(stderr, "Error: out of memory\n");
      xCloser(sCsv.in);
      return 1;
    }
    nByte = strlen30(zSql);
    rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);

    if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
      char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
      char cSep = '(';
      while( csv_read_one_field(&sCsv) ){
        zCreate = sqlite3_mprintf("%z%c\n  \"%s\" TEXT", zCreate, cSep, sCsv.z);
        cSep = ',';
        if( sCsv.cTerm!=sCsv.cSeparator ) break;







>







2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
    if( zSql==0 ){
      fprintf(stderr, "Error: out of memory\n");
      xCloser(sCsv.in);
      return 1;
    }
    nByte = strlen30(zSql);
    rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
    csv_append_char(&sCsv, 0);    /* To ensure sCsv.z is allocated */
    if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
      char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
      char cSep = '(';
      while( csv_read_one_field(&sCsv) ){
        zCreate = sqlite3_mprintf("%z%c\n  \"%s\" TEXT", zCreate, cSep, sCsv.z);
        cSep = ',';
        if( sCsv.cTerm!=sCsv.cSeparator ) break;

Changes to test/shell5.test.

298
299
300
301
302
303
304

305

306





307







308






































309
  forcedelete test.db
  catchcmd test.db {.mode csv
.import shell5.csv t1
  }
  sqlite3 db test.db
  db eval {SELECT *, '|' FROM t1}
} {a b { } | x y {} | p q r |}









db close














































finish_test







>

>
|
>
>
>
>
>
|
>
>
>
>
>
>
>

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

298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
  forcedelete test.db
  catchcmd test.db {.mode csv
.import shell5.csv t1
  }
  sqlite3 db test.db
  db eval {SELECT *, '|' FROM t1}
} {a b { } | x y {} | p q r |}
db close

#----------------------------------------------------------------------------
# 
reset_db
sqlite3 db test.db
do_test shell5-2.1 {
  set fd [open shell5.csv w]
  puts $fd ",hello"
  close $fd
  catchcmd test.db [string trim {
.mode csv
CREATE TABLE t1(a, b);
.import shell5.csv t1
  }]
  db eval { SELECT * FROM t1 }
} {{} hello}

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

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

do_test shell5-2.4 {
  set fd [open shell5.csv w]
  puts $fd {"xy""",hello}
  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}



finish_test