From: drh Date: Tue, 7 Feb 2012 14:22:18 +0000 (+0000) Subject: Port the command-line shell enhancements including the new --cmd option X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1bfbdcbe6d85a87fb3e5a423d1b8b77ecc534288;p=thirdparty%2Fsqlite.git Port the command-line shell enhancements including the new --cmd option to the nx-devkit branch. FossilOrigin-Name: 81ce52afb1bdb55d4585f01e7fb3ab86f81b7512 --- diff --git a/manifest b/manifest index ace8200e57..beeec998c1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Do\snot\srely\son\sthe\s_WIN32_WINNT\smacro\sas\svs2005\sdoes\snot\sdefine\sit\sby\sdefault.\nInstead,\salways\sassume\swinNT\sunless\sthe\smakefile\sexplicitly\ssets\nSQLITE_OS_WINNT=0. -D 2012-01-30T16:13:51.395 +C Port\sthe\scommand-line\sshell\senhancements\sincluding\sthe\snew\s--cmd\soption\nto\sthe\snx-devkit\sbranch. +D 2012-02-07T14:22:18.660 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -181,7 +181,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 365ab1c870e38596d6869e76fb544fe6e4ffc809 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c 80f3ac44a8514b1d107b80f5df4a424ae059d2b6 -F src/shell.c 670644f7bd82073ce0c97c6bff94be04c326beb8 +F src/shell.c 92e96bf5e465d63c55c5fe7fca38228c67ce7682 F src/sqlite.h.in 84cd7be33f5bf39329e018f93eb34b4a345c9c23 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 F src/sqliteInt.h f412e020e1009163c74be56eaac1bf7f6c0a4515 @@ -980,7 +980,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 2a7170f03c746473aca38ddc4b4a4091fe8331eb -R 7771b0501bb9a724c8846121d659b1dd +P 4f0997c7fab79cb7f12cf30f5ea5c87ce96bc266 +R 561353e13bf2215777cfa1f6329ca757 U drh -Z 922c1cdd3a1ee3105226ea9e60bd0622 +Z 522078f8b1fa54d140d6d449ff1e7d5c diff --git a/manifest.uuid b/manifest.uuid index d9dee506b9..6cd1ed19bd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4f0997c7fab79cb7f12cf30f5ea5c87ce96bc266 \ No newline at end of file +81ce52afb1bdb55d4585f01e7fb3ab86f81b7512 \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 503d8a6a8d..9d67eb9009 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2657,29 +2657,30 @@ static int process_sqliterc( ** Show available command line options */ static const char zOptions[] = - " -help show this message\n" - " -init filename read/process named file\n" - " -echo print commands before execution\n" - " -[no]header turn headers on or off\n" " -bail stop after hitting an error\n" - " -interactive force interactive I/O\n" " -batch force batch I/O\n" " -column set output mode to 'column'\n" + " -cmd command run \"command\" before reading stdin\n" " -csv set output mode to 'csv'\n" + " -echo print commands before execution\n" + " -init filename read/process named file\n" + " -[no]header turn headers on or off\n" + " -help show this message\n" " -html set output mode to HTML\n" + " -interactive force interactive I/O\n" " -line set output mode to 'line'\n" " -list set output mode to 'list'\n" +#ifdef SQLITE_ENABLE_MULTIPLEX + " -multiplex enable the multiplexor VFS\n" +#endif + " -nullvalue 'text' set text string for NULL values\n" " -separator 'x' set output field separator (|)\n" " -stats print memory stats before each finalize\n" - " -nullvalue 'text' set text string for NULL values\n" " -version show SQLite version\n" " -vfs NAME use NAME as the default VFS\n" #ifdef SQLITE_ENABLE_VFSTRACE " -vfstrace enable tracing of all VFS calls\n" #endif -#ifdef SQLITE_ENABLE_MULTIPLEX - " -multiplex enable the multiplexor VFS\n" -#endif ; static void usage(int showDetail){ fprintf(stderr, @@ -2742,19 +2743,22 @@ int main(int argc, char **argv){ char *z; if( argv[i][0]!='-' ) break; z = argv[i]; - if( z[0]=='-' && z[1]=='-' ) z++; - if( strcmp(argv[i],"-separator")==0 || strcmp(argv[i],"-nullvalue")==0 ){ + if( z[1]=='-' ) z++; + if( strcmp(z,"-separator")==0 + || strcmp(z,"-nullvalue")==0 + || strcmp(z,"-cmd")==0 + ){ i++; - }else if( strcmp(argv[i],"-init")==0 ){ + }else if( strcmp(z,"-init")==0 ){ i++; zInitFile = argv[i]; /* Need to check for batch mode here to so we can avoid printing ** informational messages (like from process_sqliterc) before ** we do the actual processing of arguments later in a second pass. */ - }else if( strcmp(argv[i],"-batch")==0 ){ + }else if( strcmp(z,"-batch")==0 ){ stdin_is_interactive = 0; - }else if( strcmp(argv[i],"-heap")==0 ){ + }else if( strcmp(z,"-heap")==0 ){ #if defined(SQLITE_ENABLE_MEMSYS3) || defined(SQLITE_ENABLE_MEMSYS5) int j, c; const char *zSize; @@ -2771,7 +2775,7 @@ int main(int argc, char **argv){ sqlite3_config(SQLITE_CONFIG_HEAP, malloc((int)szHeap), (int)szHeap, 64); #endif #ifdef SQLITE_ENABLE_VFSTRACE - }else if( strcmp(argv[i],"-vfstrace")==0 ){ + }else if( strcmp(z,"-vfstrace")==0 ){ extern int vfstrace_register( const char *zTraceName, const char *zOldVfsName, @@ -2782,11 +2786,11 @@ int main(int argc, char **argv){ vfstrace_register("trace",0,(int(*)(const char*,void*))fputs,stderr,1); #endif #ifdef SQLITE_ENABLE_MULTIPLEX - }else if( strcmp(argv[i],"-multiplex")==0 ){ + }else if( strcmp(z,"-multiplex")==0 ){ extern int sqlite3_multiple_initialize(const char*,int); sqlite3_multiplex_initialize(0, 1); #endif - }else if( strcmp(argv[i],"-vfs")==0 ){ + }else if( strcmp(z,"-vfs")==0 ){ sqlite3_vfs *pVfs = sqlite3_vfs_find(argv[++i]); if( pVfs ){ sqlite3_vfs_register(pVfs, 1); @@ -2868,7 +2872,8 @@ int main(int argc, char **argv){ }else if( strcmp(z,"-separator")==0 ){ i++; if(i>=argc){ - fprintf(stderr,"%s: Error: missing argument for option: %s\n", Argv0, z); + fprintf(stderr,"%s: Error: missing argument for option: %s\n", + Argv0, z); fprintf(stderr,"Use -help for a list of options.\n"); return 1; } @@ -2877,7 +2882,8 @@ int main(int argc, char **argv){ }else if( strcmp(z,"-nullvalue")==0 ){ i++; if(i>=argc){ - fprintf(stderr,"%s: Error: missing argument for option: %s\n", Argv0, z); + fprintf(stderr,"%s: Error: missing argument for option: %s\n", + Argv0, z); fprintf(stderr,"Use -help for a list of options.\n"); return 1; } @@ -2912,8 +2918,26 @@ int main(int argc, char **argv){ }else if( strcmp(z,"-multiplex")==0 ){ i++; #endif - }else if( strcmp(z,"-help")==0 || strcmp(z, "--help")==0 ){ + }else if( strcmp(z,"-help")==0 ){ usage(1); + }else if( strcmp(z,"-cmd")==0 ){ + if( i==argc-1 ) break; + i++; + z = argv[i]; + if( z[0]=='.' ){ + rc = do_meta_command(z, &data); + if( rc && bail_on_error ) return rc; + }else{ + open_db(&data); + rc = shell_exec(data.db, z, shell_callback, &data, &zErrMsg); + if( zErrMsg!=0 ){ + fprintf(stderr,"Error: %s\n", zErrMsg); + if( bail_on_error ) return rc!=0 ? rc : 1; + }else if( rc!=0 ){ + fprintf(stderr,"Error: unable to process SQL \"%s\"\n", z); + if( bail_on_error ) return rc; + } + } }else{ fprintf(stderr,"%s: Error: unknown option: %s\n", Argv0, z); fprintf(stderr,"Use -help for a list of options.\n");