God bless you sir. -----Original Message----- From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On Behalf Of Keith Medcalf Sent: Monday, September 18, 2017 12:34 PM To: SQLite mailing list Subject: Re: [sqlite] Number of rows in answer set
This patch to shell.c will "fix" the ctrl-c ... This is for an older version of shell.c, so you may have to fiddle to apply the patch to the current version. However, it does work (on Windows). --- shell.c +++ shell.c @@ -794,20 +794,35 @@ if( bSep ){ fprintf(p->out, "%s", p->colSeparator); } } -#ifdef SIGINT +#if defined(SIGINT) || defined(_WIN32) || defined(WIN32) /* ** This routine runs when the user presses Ctrl-C */ static void interrupt_handler(int NotUsed){ UNUSED_PARAMETER(NotUsed); seenInterrupt++; if( seenInterrupt>2 ) exit(1); if( db ) sqlite3_interrupt(db); } + +#if defined(_WIN32) || defined(WIN32) +/* +** Windows event handler +*/ +BOOL WINAPI CtrlHandler(DWORD dwType){ + switch( dwType ){ + case CTRL_C_EVENT: + interrupt_handler(0); + return TRUE; + default: + return FALSE; + } +} +#endif #endif /* ** This is the callback routine that the shell ** invokes for each row of a query result. @@ -4384,10 +4399,12 @@ /* Make sure we have a valid signal handler early, before anything ** else is done. */ #ifdef SIGINT signal(SIGINT, interrupt_handler); +#elif defined(WIN32) || defined(_WIN32) + SetConsoleCtrlHandler(CtrlHandler, TRUE); #endif #ifdef SQLITE_SHELL_DBNAME_PROC { /* If the SQLITE_SHELL_DBNAME_PROC macro is defined, then it is the name --- The fact that there's a Highway to Hell but only a Stairway to Heaven says a lot about anticipated traffic volume. >-----Original Message----- >From: sqlite-users [mailto:sqlite-users- >boun...@mailinglists.sqlite.org] On Behalf Of David Raymond >Sent: Monday, 18 September, 2017 09:32 >To: SQLite mailing list >Subject: Re: [sqlite] Number of rows in answer set > >As far as a use case, something like this would be great for use in >the CLI for example. Sometimes I'll run a query expecting a dozen >results only to get page after page scrolling by. Having something >akin to "select changes();" that returns an instant answer of how >many were selected would be great, as opposed to re-running the whole >query as a "select count(*) from (original query);" Or something like >the .changes option that would show a final line of "selected: >123,456 rows" > >Side note: The page after page of unexpected results scrolling by is >why I'd love a ctrl-c event in the CLI that stops the current query >but keeps the connection open. If I've attached a few databases and >populated a handful of temp tables then it's a choice of getting some >coffee while all the results scroll by, or killing it and spending >the same time re-populating the temp tables. There's no way to just >stop the query and keep the CLI open. (That I'm aware of anyway) >_______________________________________________ >sqlite-users mailing list >sqlite-users@mailinglists.sqlite.org >http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users