1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Give sqldiff --visible-controls option to deal with non-graphic text content robustly across platforms

FossilOrigin-Name: 68d2373f5d578cf3aff9d1ac4b1ab3ac00b466e94e1eb516523fc7660dfc0549
This commit is contained in:
larrybr
2021-07-26 18:28:24 +00:00
parent 3740712677
commit e40875d211
3 changed files with 46 additions and 15 deletions

View File

@@ -34,6 +34,7 @@ struct GlobalVars {
int bSchemaOnly; /* Only show schema differences */
int bSchemaPK; /* Use the schema-defined PK, not the true PK */
int bHandleVtab; /* Handle fts3, fts4, fts5 and rtree vtabs */
int bDarkCtl; /* Render controls in text as blob literals */
unsigned fDebug; /* Debug flags */
sqlite3 *db; /* The database connection */
} g;
@@ -386,13 +387,39 @@ static void printQuoted(FILE *out, sqlite3_value *X){
fprintf(out, "NULL");
}else{
fprintf(out, "'");
for(i=j=0; zArg[i]; i++){
if( zArg[i]=='\'' ){
fprintf(out, "%.*s'", i-j+1, &zArg[j]);
j = i+1;
}
}
fprintf(out, "%s'", &zArg[j]);
if( !g.bDarkCtl ){
for(i=j=0; zArg[i]; i++){
if( zArg[i]=='\'' ){
fprintf(out, "%.*s'", i-j+1, &zArg[j]);
j = i+1;
}
}
fprintf(out, "%s'", &zArg[j]);
}else{
int inctl = 0;
for(i=j=0; zArg[i]; i++){
char c = zArg[i];
int ctl = iscntrl(c);
if( ctl>inctl ){
inctl = ctl;
fprintf(out, "%.*s'||X'%02x", i-j, &zArg[j], c);
j = i+1;
}else if( ctl ){
fprintf(out, "%02x", c);
j = i+1;
}else{
if( inctl ){
inctl = 0;
fprintf(out, "'\n||'");
}
if( c=='\'' ){
fprintf(out, "%.*s'", i-j+1, &zArg[j]);
j = i+1;
}
}
}
fprintf(out, "%s'", &zArg[j]);
}
}
break;
}
@@ -1875,6 +1902,7 @@ static void showHelp(void){
" --table TAB Show only differences in table TAB\n"
" --transaction Show SQL output inside a transaction\n"
" --vtab Handle fts3, fts4, fts5 and rtree tables\n"
" --visible-controls Render controls in text as blob literals\n"
);
}
@@ -1948,6 +1976,9 @@ int main(int argc, char **argv){
if( strcmp(z,"vtab")==0 ){
g.bHandleVtab = 1;
}else
if( strcmp(z, "visible-controls")==0 ){
g.bDarkCtl = 1;
}else
{
cmdlineError("unknown option: %s", argv[i]);
}