Fossil SCM

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.

jan.nijtmans 2014-05-26 20:55 trunk
Commit 87130593e41264e47dfe84b085817bd7cb689931
1 file changed +1
--- src/shell.c
+++ src/shell.c
@@ -2429,10 +2429,11 @@
24292429
xCloser(sCsv.in);
24302430
return 1;
24312431
}
24322432
nByte = strlen30(zSql);
24332433
rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2434
+ csv_append_char(&sCsv, 0); /* To ensure sCsv.z is allocated */
24342435
if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
24352436
char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
24362437
char cSep = '(';
24372438
while( csv_read_one_field(&sCsv) ){
24382439
zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
24392440
--- src/shell.c
+++ src/shell.c
@@ -2429,10 +2429,11 @@
2429 xCloser(sCsv.in);
2430 return 1;
2431 }
2432 nByte = strlen30(zSql);
2433 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
 
2434 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2435 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2436 char cSep = '(';
2437 while( csv_read_one_field(&sCsv) ){
2438 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2439
--- src/shell.c
+++ src/shell.c
@@ -2429,10 +2429,11 @@
2429 xCloser(sCsv.in);
2430 return 1;
2431 }
2432 nByte = strlen30(zSql);
2433 rc = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
2434 csv_append_char(&sCsv, 0); /* To ensure sCsv.z is allocated */
2435 if( rc && sqlite3_strglob("no such table: *", sqlite3_errmsg(db))==0 ){
2436 char *zCreate = sqlite3_mprintf("CREATE TABLE %s", zTable);
2437 char cSep = '(';
2438 while( csv_read_one_field(&sCsv) ){
2439 zCreate = sqlite3_mprintf("%z%c\n \"%s\" TEXT", zCreate, cSep, sCsv.z);
2440

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button