From: drh Date: Fri, 11 Nov 2016 04:37:00 +0000 (+0000) Subject: Add the --raw option to the ".read" dot-command of the command-line shell, X-Git-Tag: version-3.16.0~135 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c5b86be7db42b78909dfabe5f8fc0733773a0b90;p=thirdparty%2Fsqlite.git 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 --- diff --git a/manifest b/manifest index cfad1a2249..51a0a7d02f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Take\scare\snot\sto\stry\sto\sgenerate\scode\sfor\sthe\sATTACH\sand\sDETACH\scommands\nif\sthere\swere\ssyntax\serrors\sduring\sparsing.\nFix\sfor\sticket\s[2f1b168ab4d4844] -D 2016-11-11T03:37:24.086 +C Add\sthe\s--raw\soption\sto\sthe\s".read"\sdot-command\sof\sthe\scommand-line\sshell,\nto\scause\sthe\snamed\sfile\sto\sbe\sread\sand\ssent\sdirectly\sinto\ssqlite3_exec()\nwithout\sany\sinterpretation. +D 2016-11-11T04:37:00.671 F Makefile.in 6fd48ffcf7c2deea7499062d1f3747f986c19678 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc e0217f2d35a0448abbe4b066132ae20136e8b408 @@ -388,7 +388,7 @@ F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/resolve.c 3fac1b2737ea5a724f20b921ac7e259c9be2100b F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/select.c ea3af83e2d0f245fef81ea4cf04cb730ce67f722 -F src/shell.c 63e54cfa1c7ec5b70a4c9a86502bc10280c3d5a3 +F src/shell.c e77c47b035e7ac79c89ca25fdb4fbc7158a86a20 F src/sqlite.h.in 803f7050f69b2eea573fac219f3c92582c096027 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 8648034aa702469afb553231677306cc6492a1ae @@ -1530,7 +1530,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P b4889588246c33374ff3758e21ccc4ce246380b6 -R 26247ef800afdc7745db1d52a3a74bf0 +P b0ff183b8ffdbebece06cfea1c6781fc0e8e8547 +R 1bc28093103f82773b6175c0eaf36791 U drh -Z bdc6c3a824c3e2f132fc99deec6951e5 +Z 12078e4f7b8e85a9a59383108eda95de diff --git a/manifest.uuid b/manifest.uuid index be53f11adc..271b3c84d2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b0ff183b8ffdbebece06cfea1c6781fc0e8e8547 \ No newline at end of file +09233770b24d69a305556241a6beeb5e4d77c0d7 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 6a7bee142d..8c352e87c8 100644 --- a/src/shell.c +++ b/src/shell.c @@ -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