From: drh Date: Mon, 4 Feb 2019 14:53:18 +0000 (+0000) Subject: Add the ".progress" command to the CLI. X-Git-Tag: version-3.27.0~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3f83f591541b562b39c2b9cf8b9fcfab54d535e7;p=thirdparty%2Fsqlite.git Add the ".progress" command to the CLI. FossilOrigin-Name: ad84ca24ff760f7a2b128f2eeb4d799a97f84b8b8a8bb8d9657c4c555f6ccf47 --- diff --git a/manifest b/manifest index b1d27f1db9..807b34a7fb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sanother\spotential\sbuffer\soverread\sin\sfts5. -D 2019-02-04T14:00:20.889 +C Add\sthe\s".progress"\scommand\sto\sthe\sCLI. +D 2019-02-04T14:53:18.530 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 178d8eb6840771149cee40b322d1b3be30d330198c522c903c1b66fb5a1bfca4 @@ -515,7 +515,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c c8f207247472c41ac73d738e1c1a80719ad253d1dbb617ed57740492b2a6c097 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 F src/select.c 8e22fda41a737c391e8b797f7c71e7ded1d107c31181b07bb10b3d4f22a28cd9 -F src/shell.c.in 705a00be4fa43303b6b18df2241f5397cefd8d9f076bb035ad01b42635c7a1de +F src/shell.c.in d9898bedbddb8b47dcb07c0b948addfe312e76af0ccfc42d2bedac9634153557 F src/sqlite.h.in 7da74fd5bd7a9dbe92297060f036935520b26e240457287c5e67c7b9db51a986 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 960f1b86c3610fa23cb6a267572a97dcf286e77aa0dd3b9b23292ffaa1ea8683 @@ -1804,7 +1804,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 e608085d3f7e3cc0015fde626e205ee9842ef3cd06dc879fbbc7f2067c592965 -R 5b0a9d78197ef0ddde028de705d5dd68 -U dan -Z 88407bf623e9d02a54fc59e1f78deaa8 +P 14fba4cc5db2bc206f024bfa5dd82fffdbc7577162da2c3b15a91cc1c91f3846 +R dfe82ebd7478b9a85403422449ab407a +U drh +Z d147cbcb5347a91cfedf57995c7ee3d2 diff --git a/manifest.uuid b/manifest.uuid index 7d033e6615..9395b86eed 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -14fba4cc5db2bc206f024bfa5dd82fffdbc7577162da2c3b15a91cc1c91f3846 \ No newline at end of file +ad84ca24ff760f7a2b128f2eeb4d799a97f84b8b8a8bb8d9657c4c555f6ccf47 \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index 41832906ac..746caaedc0 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -1028,6 +1028,9 @@ struct ShellState { int writableSchema; /* True if PRAGMA writable_schema=ON */ int showHeader; /* True to show column names in List or Column mode */ int nCheck; /* Number of ".check" commands run */ + unsigned nProgress; /* Number of progress callbacks encountered */ + unsigned mxProgress; /* Maximum progress callbacks before failing */ + unsigned flgProgress; /* Flags for the progress callback */ unsigned shellFlgs; /* Various flags */ sqlite3_int64 szMax; /* --maxsize argument to .open */ char *zDestTable; /* Name of destination table when MODE_Insert */ @@ -1082,6 +1085,13 @@ struct ShellState { #define SHELL_TRACE_EXPANDED 1 /* Show expanded SQL text */ #define SHELL_TRACE_NORMALIZED 2 /* Show normalized SQL text */ +/* Bits in the ShellState.flgProgress variable */ +#define PROGRESS_QUIET 0x01 /* Omit announcing every progress callback */ +#define PROGRESS_RESET 0x02 /* Reset the count when the progres + ** callback limit is reached, and for each + ** top-level SQL statement */ +#define PROGRESS_ONCE 0x04 /* Cancel the --limit after firing once */ + /* ** These are the allowed shellFlgs values */ @@ -1782,6 +1792,24 @@ static void eqp_render(ShellState *p){ } } +/* +** Progress handler callback. +*/ +static int progress_handler(void *pClientData) { + ShellState *p = (ShellState*)pClientData; + p->nProgress++; + if( p->nProgress>=p->mxProgress && p->mxProgress>0 ){ + raw_printf(p->out, "Progress limit reached (%u)\n", p->nProgress); + if( p->flgProgress & PROGRESS_RESET ) p->nProgress = 0; + if( p->flgProgress & PROGRESS_ONCE ) p->mxProgress = 0; + return 1; + } + if( (p->flgProgress & PROGRESS_QUIET)==0 ){ + raw_printf(p->out, "Progress %u\n", p->nProgress); + } + return 0; +} + /* ** This is the callback routine that the shell ** invokes for each row of a query result. @@ -3468,6 +3496,11 @@ static const char *(azHelp[]) = { ".output ?FILE? Send output to FILE or stdout if FILE is omitted", " If FILE begins with '|' then open it as a pipe.", ".print STRING... Print literal STRING", + ".progress N Invoke progress handler after every N opcodes", + " --limit N Interrupt after N progress callbacks", + " --once Do no more than one progress interrupt", + " --quiet|-q No output except at interrupts", + " --reset Reset the count for each input and interrupt", ".prompt MAIN CONTINUE Replace the standard prompts", ".quit Exit this program", ".read FILE Read input from FILE", @@ -7000,6 +7033,50 @@ static int do_meta_command(char *zLine, ShellState *p){ raw_printf(p->out, "\n"); }else + if( c=='p' && n>=3 && strncmp(azArg[0], "progress", n)==0 ){ + int i; + int n = 0; + p->flgProgress = 0; + p->mxProgress = 0; + p->nProgress = 0; + for(i=1; iflgProgress |= PROGRESS_QUIET; + continue; + } + if( strcmp(z,"reset")==0 ){ + p->flgProgress |= PROGRESS_RESET; + continue; + } + if( strcmp(z,"once")==0 ){ + p->flgProgress |= PROGRESS_ONCE; + continue; + } + if( strcmp(z,"limit")==0 ){ + if( i+1>=nArg ){ + utf8_printf(stderr, "Error: missing argument on --limit\n"); + rc = 1; + goto meta_command_exit; + }else{ + p->mxProgress = (int)integerValue(azArg[++i]); + } + continue; + } + utf8_printf(stderr, "Error: unknown option: \"%s\"\n", azArg[i]); + rc = 1; + goto meta_command_exit; + }else{ + n = (int)integerValue(z); + } + } + open_db(p, 0); + sqlite3_progress_handler(p->db, n, progress_handler, p); + }else + if( c=='p' && strncmp(azArg[0], "prompt", n)==0 ){ if( nArg >= 2) { strncpy(mainPrompt,azArg[1],(int)ArraySize(mainPrompt)-1); @@ -8335,6 +8412,7 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){ open_db(p, 0); if( ShellHasFlag(p,SHFLG_Backslash) ) resolve_backslashes(zSql); + if( p->flgProgress & PROGRESS_RESET ) p->nProgress = 0; BEGIN_TIMER; rc = shell_exec(p, zSql, &zErrMsg); END_TIMER;