Re: [sqlite] Re: Terminating long query in C ?
Tuesday, October 10, 2006, 9:32:18 PM, Mohd Radzi Ibrahim wrote: > Thank you guys for the suggestion. That's what I really need. Which one is > better, the sqlite3_interrupt() or sqlite3_progress_handler()? My gut > feeling is that sqlite3_interrupt() should be better since it does not > interfere with the running of the query until it is signaled. Besides, the > progress_handler does not actually give me the right proportion of > completion... Or is there a way I can know proportion of completion from > it? Suggestion: Create an (atomically accessible) global variable. At the start of your query set it to zero and start a timer. Give sqlite3_progress_handler() a function that simply returns the variable. When the timer expires (or control-C is pressed) atomically set the variable to one. If you use a large value for nOps in sqlite3_progress_handler() the overhead should be very small. e > - Original Message - > From: "Igor Tandetnik" <[EMAIL PROTECTED]> > To: "SQLite" <sqlite-users@sqlite.org> > Sent: Wednesday, October 11, 2006 8:43 AM > Subject: [sqlite] Re: Terminating long query in C ? >> [EMAIL PROTECTED] wrote: >>> sqlite3_interrupt() has long been used by the sqlite3 shell program. >>> When you press control-C a posix signal handler invokes >>> sqlite3_interrupt() to stop the current query. (This only works on >>> posix, of course.) The original purpose of sqlite3_interrupt() was >>> to support ^C in the shell, and for that purpose the thread >>> restriction >>> was entirely reasonable. >>> >>> It is easy to understand how this use of sqlite3_interrupt() might >>> have escaped the notice of users on non-posix systems. >> >> One can register a Ctrl-C handler on Windows with SetConsoleCtrlHandler. >> But the handler is invoked on a background thread created by the system >> specifically for this purpose, so sqlite3_interrupt couldn't be used >> there, either. >> >> Igor Tandetnik -- Doug Currie Londonderry, NH - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Re: Terminating long query in C ?
Thank you guys for the suggestion. That's what I really need. Which one is better, the sqlite3_interrupt() or sqlite3_progress_handler()? My gut feeling is that sqlite3_interrupt() should be better since it does not interfere with the running of the query until it is signaled. Besides, the progress_handler does not actually give me the right proportion of completion... Or is there a way I can know proportion of completion from it? thanks again, Radzi. - Original Message - From: "Igor Tandetnik" <[EMAIL PROTECTED]> To: "SQLite" <sqlite-users@sqlite.org> Sent: Wednesday, October 11, 2006 8:43 AM Subject: [sqlite] Re: Terminating long query in C ? [EMAIL PROTECTED] wrote: sqlite3_interrupt() has long been used by the sqlite3 shell program. When you press control-C a posix signal handler invokes sqlite3_interrupt() to stop the current query. (This only works on posix, of course.) The original purpose of sqlite3_interrupt() was to support ^C in the shell, and for that purpose the thread restriction was entirely reasonable. It is easy to understand how this use of sqlite3_interrupt() might have escaped the notice of users on non-posix systems. One can register a Ctrl-C handler on Windows with SetConsoleCtrlHandler. But the handler is invoked on a background thread created by the system specifically for this purpose, so sqlite3_interrupt couldn't be used there, either. Igor Tandetnik - To unsubscribe, send email to [EMAIL PROTECTED] - - To unsubscribe, send email to [EMAIL PROTECTED] -
[sqlite] Re: Terminating long query in C ?
[EMAIL PROTECTED] wrote: sqlite3_interrupt() has long been used by the sqlite3 shell program. When you press control-C a posix signal handler invokes sqlite3_interrupt() to stop the current query. (This only works on posix, of course.) The original purpose of sqlite3_interrupt() was to support ^C in the shell, and for that purpose the thread restriction was entirely reasonable. It is easy to understand how this use of sqlite3_interrupt() might have escaped the notice of users on non-posix systems. One can register a Ctrl-C handler on Windows with SetConsoleCtrlHandler. But the handler is invoked on a background thread created by the system specifically for this purpose, so sqlite3_interrupt couldn't be used there, either. Igor Tandetnik - To unsubscribe, send email to [EMAIL PROTECTED] -
[sqlite] Re: Terminating long query in C ?
Mohd Radzi Ibrahim <[EMAIL PROTECTED]> wrote: How do I cancel a long running query? There are two ways I know of. You can register a progress handler - see sqlite3_progress_handler. The handler is called periodically while the query is running, and has the option to interrupt the query. Another way is to use sqlite3_interrupt. Before SQLite 3.3.7 (which I believe is the latest version at this time), sqlite3_interrupt could only be called from the same thread that created the connection, which as far as I can tell renders the function completely useless. With SQLite 3.3.7 it can be called from a different thread. So make sure to download the latest version. Igor Tandetnik - To unsubscribe, send email to [EMAIL PROTECTED] -