aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2021-11-18 15:40:05 +0000
committerdrh <>2021-11-18 15:40:05 +0000
commit9cd0c3d4c5ccdb7fd2ae7e47aeefe33517f8a56c (patch)
tree9a03f4668c5aa1264205af7f105aad5ee169d5a9 /src
parente41d30ffdd4ac37d55089c0eecba5239e7fa3cc8 (diff)
downloadsqlite-9cd0c3d4c5ccdb7fd2ae7e47aeefe33517f8a56c.tar.gz
sqlite-9cd0c3d4c5ccdb7fd2ae7e47aeefe33517f8a56c.zip
Improve CSV quoting in the CLI using the strstr() function.
FossilOrigin-Name: b7927bf91049c903730a280484bbcdcdedc259a31fbcc3d3b0c7d046ec321633
Diffstat (limited to 'src')
-rw-r--r--src/shell.c.in13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/shell.c.in b/src/shell.c.in
index 672c80a25..b4b4e2fcc 100644
--- a/src/shell.c.in
+++ b/src/shell.c.in
@@ -1762,19 +1762,14 @@ static void output_csv(ShellState *p, const char *z, int bSep){
if( z==0 ){
utf8_printf(out,"%s",p->nullValue);
}else{
- int i;
- int nSep = strlen30(p->colSeparator);
- int n = strlen30(z);
- for(i=0; i<n; i++){
- if( needCsvQuote[((unsigned char*)z)[i]]
- || (z[i]==p->colSeparator[0] &&
- (nSep==1 || (i+nSep<n && memcmp(z+i, p->colSeparator, nSep)==0)))
- ){
+ unsigned i;
+ for(i=0; z[i]; i++){
+ if( needCsvQuote[((unsigned char*)z)[i]] ){
i = 0;
break;
}
}
- if( i==0 ){
+ if( i==0 || strstr(z, p->colSeparator)!=0 ){
char *zQuoted = sqlite3_mprintf("\"%w\"", z);
utf8_printf(out, "%s", zQuoted);
sqlite3_free(zQuoted);