1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-01 06:27:03 +03:00

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
This commit is contained in:
drh
2025-02-24 17:50:49 +00:00
parent b6205d4bc3
commit e4f7af1908
4 changed files with 199 additions and 12 deletions

View File

@ -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);