1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-03 16:53:36 +03:00

Add the --raw option to the ".read" dot-command of the command-line shell,

to cause the named file to be read and sent directly into sqlite3_exec()
without any interpretation.

FossilOrigin-Name: 09233770b24d69a305556241a6beeb5e4d77c0d7
This commit is contained in:
drh
2016-11-11 04:37:00 +00:00
parent 4360fcea6d
commit c5b86be7db
3 changed files with 47 additions and 15 deletions

View File

@@ -4205,18 +4205,50 @@ static int do_meta_command(char *zLine, ShellState *p){
if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 ){
FILE *alt;
if( nArg!=2 ){
raw_printf(stderr, "Usage: .read FILE\n");
char *zFile;
int rawMode = 0;
if( nArg!=2 && nArg!=3 ){
raw_printf(stderr, "Usage: .read [--raw] FILE\n");
rc = 1;
goto meta_command_exit;
}
alt = fopen(azArg[1], "rb");
if( alt==0 ){
utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
rc = 1;
if( nArg==3 ){
const char *z = azArg[1];
while( z[0]=='-' ) z++;
if( strcmp(z,"raw")==0 ){
rawMode = 1;
}
else{
raw_printf(stderr, "unknown option: \"%s\"\n", azArg[1]);
rc = 1;
goto meta_command_exit;
}
}
zFile = azArg[nArg-1];
if( rawMode ){
char *z = readFile(zFile);
if( z==0 ){
utf8_printf(stderr, "Error: cannot open \"%s\"\n", zFile);
rc = 1;
}else{
char *zErr = 0;
open_db(p, 1);
rc = sqlite3_exec(p->db, z, callback, p, &zErr);
sqlite3_free(z);
if( zErr ){
utf8_printf(stdout, "%s", zErr);
sqlite3_free(zErr);
}
}
}else{
rc = process_input(p, alt);
fclose(alt);
alt = fopen(zFile, "rb");
if( alt==0 ){
utf8_printf(stderr,"Error: cannot open \"%s\"\n", azArg[1]);
rc = 1;
}else{
rc = process_input(p, alt);
fclose(alt);
}
}
}else