progress handler from user functions
(1) By Max (Maxulite) on 2020-03-29 17:08:29 [source]
Hi My function might wait for some condition to be met (even as simple as delay), but I would like to software still be responsive during these period. Can the user function use the progress handler that was registered with sqlite3_progress_handler directly? And if it's not a good idea, is there some sqlite3_ call I might invoke in order to achieve this? Thanks Max
(2) By anonymous on 2020-03-29 21:26:31 in reply to 1 [link] [source]
Something I have done is preparing the statement "
WITH X AS (SELECT 0 UNION ALL SELECT 0 FROM X) SELECT 0 FROM X;" and stepping it when it wants to check for interrupts. However, this seems a messy way to do it.
(3) By Gunter Hick (gunter_hick) on 2020-03-30 06:46:29 in reply to 1 [link] [source]
What are you actually trying to do? What "my function" are you talking about? The progress handler is a function written by yourself that you ask to SQLite to call after every N virtual machine instructions are executed. It's only purpose is to notify your application that N virtual machine instructions have been executed and the query is still not completed. Your progress handler is then required to return 0 (continue) or non-zero (interrupt), in the latter case, the query will be terminated immediately, without returning another row. Calling the progress handler function directly does nothing to SQLite. Perhaps you are looking for the sqlite3_interrupt() function. Calling this function will terminate the execution of any currently running query on the referenced database Connection.
(4) By Max (Maxulite) on 2020-03-30 09:33:01 in reply to 3 [link] [source]
I thought maybe for some reasons, the context of calling the progress handler and user function might be different for sqlite. But according to the docs, the progress handler is already quite restricted in what it can do (no database connection modification). Also common sense hints that both are quite "external" for Sqlite. Probably the main concern for me in this case is to get the progress handler I registered previously. In my case it's not global, but specific for particular database connection oop object. I'm sure there's no sqlite3_get_progress_handler or something like this in api, so probably I will have to implement some global registration to obtain the handler of a database connection from the global context of user functions.
(5) By Gunter Hick (gunter_hick) on 2020-03-30 12:25:58 in reply to 4 [link] [source]
There is a "Highlander restriction" on the progress handler. There can only be one (per Connection). And the application is expected to know which one to set. So yes, if you need to know the registered handler, you must track this info yourself.