Improve CSV quoting in the CLI using the strstr() function.

FossilOrigin-Name: b7927bf91049c903730a280484bbcdcdedc259a31fbcc3d3b0c7d046ec321633
This commit is contained in:
drh
2021-11-18 15:40:05 +00:00
parent e41d30ffdd
commit 9cd0c3d4c5
3 changed files with 11 additions and 16 deletions
+4 -9
View File
@@ -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);