aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlarrybr <larrybr@noemail.net>2023-09-12 23:21:39 +0000
committerlarrybr <larrybr@noemail.net>2023-09-12 23:21:39 +0000
commit111815609cb6d12d2f33bde46a3fdea8c9614997 (patch)
tree520816faee7bcf52f74f6039fed91468b2a47e78 /src
parent12439f9c16bc4a98a91bcad486870a1366acbfb5 (diff)
downloadsqlite-111815609cb6d12d2f33bde46a3fdea8c9614997.tar.gz
sqlite-111815609cb6d12d2f33bde46a3fdea8c9614997.zip
CLI .import to accept EOF in lieu of record terminator on last field of CSV (with multiple field records), per RFC 4180. [forum:5b21c25bdfa|forum post 5b21c25bdfa]
FossilOrigin-Name: 6f7842f577a28df1f809cd4bae9e8eafa26f2b54a25a1362ebbdebf5026be57c
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index 2334872e5..2d382a681 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -9063,6 +9063,14 @@ static int do_meta_command(char *zLine, ShellState *p){
** the remaining columns.
*/
if( p->mode==MODE_Ascii && (z==0 || z[0]==0) && i==0 ) break;
+ /*
+ ** For CSV mode, per RFC 4180, accept EOF in lieu of final
+ ** record terminator but only for last field of multi-field row.
+ ** (If there are too few fields, it's not valid CSV anyway.)
+ */
+ if( z==0 && (xRead==csv_read_one_field) && i==nCol-1 && i>0 ){
+ z = "";
+ }
sqlite3_bind_text(pStmt, i+1, z, -1, SQLITE_TRANSIENT);
if( i<nCol-1 && sCtx.cTerm!=sCtx.cColSep ){
utf8_printf(stderr, "%s:%d: expected %d columns but found %d - "