Query timeout at connection level
(1) By Akhilesh Airen (airen977) on 2022-06-25 07:11:47 [link] [source]
Is there any timeout parameter which could be setup at connection level, which is maximum amount of time a select query may take and if it is exceeding that parameter, query will just return an error code?
Thanks
(2) By David Jones (vman59) on 2022-06-25 12:05:55 in reply to 1 [link] [source]
You could write a progress handler that performs a timeout check.
https://sqlite.org/c3ref/progress_handler.html
(3) By Simon Slavin (slavin) on 2022-06-25 19:49:23 in reply to 1 [link] [source]
Are you talking about this:
https://www.sqlite.org/pragma.html#pragma_busy_timeout
(with its equivalents which can be set through the API without a SQL command) ?
If you don't set up a busy handler, a SQL command which exceeds the timeout you set returns SQLITE_BUSY
.
(4) By Stephan Beal (stephan) on 2022-06-25 19:57:18 in reply to 3 [link] [source]
... a SQL command which exceeds the timeout you set returns SQLITE_BUSY .
i almost posted that one earlier as well, but the docs say that the busy handler is only applicable when waiting on a lock, as opposed waiting on a long-running query.
(5) By Simon Slavin (slavin) on 2022-06-26 00:58:18 in reply to 4 [link] [source]
Yeah, I can't tell if that is actually what the OP wanted. But I thought it was worth a try. Will the kind of query they do need that kind of lock ? Can't tell until they post saying whether it works.
(6) By Simon Willison (simonw) on 2022-06-26 04:20:57 in reply to 2 [source]
I've been using this trick for a few years, it works really well. Here's my code:
Example usage: https://github.com/simonw/datasette/blob/3508bf7875f8d62b2725222f3b07747974d54b97/datasette/database.py#L230
(7) By Akhilesh Airen (airen977) on 2022-06-26 16:17:28 in reply to 4 [link] [source]
Yes, it works in contention waiting for lock, but as you said I need it for long-running query
(8) By Akhilesh Airen (airen977) on 2022-06-26 16:24:45 in reply to 6 [link] [source]
Thanks, it should work