SQLite

Check-in [9c2e7612]
Login

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

Overview
Comment:In the command-line shell for CSV import, if the lines are \r\n terminated and the last field is blank, make sure an empty string and not a "\r" string is imported.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 9c2e7612cd137895e13ee872e668ce1216719d85
User & Date: drh 2014-02-26 13:53:34
Context
2014-02-26
21:35
More efficient removal of duplicates in recursive queries using the UNION compound operator. (check-in: 06c2db87 user: drh tags: trunk)
19:05
Only run the OP_OpenRead opcodes for a correlated subquery once, on the initial iteration. Keep the cursor open for subsequent runs. This was suppose to be a performance enhancement, but it is difficult to come up with a query where is makes a significant difference. Hence, the change is getting parked in a branch. (Leaf check-in: 3ad687b7 user: drh tags: open-only-once)
13:53
In the command-line shell for CSV import, if the lines are \r\n terminated and the last field is blank, make sure an empty string and not a "\r" string is imported. (check-in: 9c2e7612 user: drh tags: trunk)
02:26
Improved handling of constants and especially constant functions in the ORDER BY clause of a query. Do not optimize out "ORDER BY random()". Fix for ticket [65bdeb9739605cc2296]. (check-in: dca1945a user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/shell.c.
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
  }else{
    while( c!=EOF && c!=cSep && c!='\n' ){
      csv_append_char(p, c);
      c = fgetc(p->in);
    }
    if( c=='\n' ){
      p->nLine++;
      if( p->n>1 && p->z[p->n-1]=='\r' ) p->n--;
    }
    p->cTerm = c;
  }
  if( p->z ) p->z[p->n] = 0;
  return p->z;
}








|







1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
  }else{
    while( c!=EOF && c!=cSep && c!='\n' ){
      csv_append_char(p, c);
      c = fgetc(p->in);
    }
    if( c=='\n' ){
      p->nLine++;
      if( p->n>0 && p->z[p->n-1]=='\r' ) p->n--;
    }
    p->cTerm = c;
  }
  if( p->z ) p->z[p->n] = 0;
  return p->z;
}

Changes to test/shell5.test.
280
281
282
283
284
285
286



















287
288
289
290
  catchcmd test.db {.mode csv
    CREATE TABLE t1(a,b,c,d);
.import shell5.csv t1
  }
  sqlite3 db test.db
  db eval {SELECT hex(c) FROM t1 ORDER BY rowid}
} {636F6C756D6E33 783320220D0A64617461222033 783320220A64617461222033}




















db close

finish_test







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




280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
  catchcmd test.db {.mode csv
    CREATE TABLE t1(a,b,c,d);
.import shell5.csv t1
  }
  sqlite3 db test.db
  db eval {SELECT hex(c) FROM t1 ORDER BY rowid}
} {636F6C756D6E33 783320220D0A64617461222033 783320220A64617461222033}

# Blank last column with \r\n line endings.
do_test shell5-1.11 {
  set out [open shell5.csv w]
  fconfigure $out -translation binary
  puts $out "column1,column2,column3\r"
  puts $out "a,b, \r"
  puts $out "x,y,\r"
  puts $out "p,q,r\r"
  close $out
  catch {db close}
  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