diff options
author | drh <> | 2025-02-24 17:50:49 +0000 |
---|---|---|
committer | drh <> | 2025-02-24 17:50:49 +0000 |
commit | e4f7af190824bfaeeb81f47fbbed5d9588cd3f8a (patch) | |
tree | 9979d1856be5c1fa089c8982a494522d223074cf /src | |
parent | b6205d4bc346c48b61d2fbba3e2030bc12e74ed5 (diff) | |
download | sqlite-e4f7af190824bfaeeb81f47fbbed5d9588cd3f8a.tar.gz sqlite-e4f7af190824bfaeeb81f47fbbed5d9588cd3f8a.zip |
Only use unistr() in columnar formats when strictly needed.
Do not use unistr() in insert mode when --escape is off.
More test cases.
FossilOrigin-Name: e029828de91b10b4c7f4a19bc70c35e4f36fae4ebf32b40553a6ba9f2b3af295
Diffstat (limited to 'src')
-rw-r--r-- | src/shell.c.in | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/shell.c.in b/src/shell.c.in index ad2215608..aed50a2cc 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -4057,6 +4057,16 @@ static char *translateForDisplayAndDup( return (char*)zOut; } +/* Return true if the text string z[] contains characters that need +** unistr() escaping. +*/ +static int needUnistr(const unsigned char *z){ + unsigned char c; + if( z==0 ) return 0; + while( (c = *z)>0x1f || c=='\t' || c=='\n' || (c=='\r' && z[1]=='\n') ){ z++; } + return c!=0; +} + /* Extract the value of the i-th current column for pStmt as an SQL literal ** value. Memory is obtained from sqlite3_malloc64() and must be freed by ** the caller. @@ -4071,7 +4081,8 @@ static char *quoted_column(sqlite3_stmt *pStmt, int i){ return sqlite3_mprintf("%s",sqlite3_column_text(pStmt,i)); } case SQLITE_TEXT: { - return sqlite3_mprintf("%#Q",sqlite3_column_text(pStmt,i)); + const unsigned char *zText = sqlite3_column_text(pStmt,i); + return sqlite3_mprintf(needUnistr(zText)?"%#Q":"%Q",zText); } case SQLITE_BLOB: { int j; @@ -10001,6 +10012,11 @@ static int do_meta_command(char *zLine, ShellState *p){ }else if( cli_strncmp(zMode,"insert",n2)==0 ){ p->mode = MODE_Insert; set_table_name(p, zTabname ? zTabname : "table"); + if( p->eEscMode==SHELL_ESC_OFF ){ + ShellSetFlag(p, SHFLG_Newlines); + }else{ + ShellClearFlag(p, SHFLG_Newlines); + } }else if( cli_strncmp(zMode,"quote",n2)==0 ){ p->mode = MODE_Quote; sqlite3_snprintf(sizeof(p->colSeparator), p->colSeparator, SEP_Comma); |