** Output a single term of CSV. Actually, p->colSeparator is used for ** the separator, which may or may not be a comma. p->nullValue is ** the null value. Strings are quoted if necessary. The separator ** is only issued if bSep is true. */
| 17073 | ** is only issued if bSep is true. |
| 17074 | */ |
| 17075 | static void output_csv(ShellState *p, const char *z, int bSep){ |
| 17076 | FILE *out = p->out; |
| 17077 | if( z==0 ){ |
| 17078 | utf8_printf(out,"%s",p->nullValue); |
| 17079 | }else{ |
| 17080 | unsigned i; |
| 17081 | for(i=0; z[i]; i++){ |
| 17082 | if( needCsvQuote[((unsigned char*)z)[i]] ){ |
| 17083 | i = 0; |
| 17084 | break; |
| 17085 | } |
| 17086 | } |
| 17087 | if( i==0 || strstr(z, p->colSeparator)!=0 ){ |
| 17088 | char *zQuoted = sqlite3_mprintf("\"%w\"", z); |
| 17089 | shell_check_oom(zQuoted); |
| 17090 | utf8_printf(out, "%s", zQuoted); |
| 17091 | sqlite3_free(zQuoted); |
| 17092 | }else{ |
| 17093 | utf8_printf(out, "%s", z); |
| 17094 | } |
| 17095 | } |
| 17096 | if( bSep ){ |
| 17097 | utf8_printf(p->out, "%s", p->colSeparator); |
| 17098 | } |
| 17099 | } |
| 17100 | |
| 17101 | /* |
| 17102 | ** This routine runs when the user presses Ctrl-C |
no test coverage detected