Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Simon Slavin
On 31 Dec 2018, at 10:44pm, Jesse Rittner wrote: > Simon Slavin-3 wrote > >> it can be long only if you're a bad SQL programmer > > To be fair, the query in question might not get run frequently enough to > warrant the overhead of maintaining an index. Fair point. Simon.

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Jesse Rittner
Simon Slavin-3 wrote > it can be long only if you're a bad SQL programmer To be fair, the query in question might not get run frequently enough to warrant the overhead of maintaining an index. -- Sent from: http://sqlite.1065341.n5.nabble.com/ ___

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Simon Slavin
On 31 Dec 2018, at 9:10pm, Jesse Rittner wrote: > Simon Slavin-3 wrote > >> You can calculate an "end time" yourself, check it each time you're ready to >> call sqlite3_step(), and jump straight to sqlite3_finalize() if your time is >> up. > > I'm not familiar with the inner workings of

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Keith Medcalf
>I don't think the interrupt call will actually terminate a step that >is actually being processed, but only mark that no more steps should >happen. In other words, I don't think SQLite is spending time >checking a flag to stop in the middle of processing a step to allow the >processing to

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Richard Damon
On 12/31/18 4:10 PM, Jesse Rittner wrote: > Simon Slavin-3 wrote >> You can calculate an "end time" yourself, check it each time you're ready >> to call sqlite3_step(), and jump straight to sqlite3_finalize() if your >> time is up. > I'm not familiar with the inner workings of sqlite3_step, but if

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Keith Medcalf
That is, of course (I forgot the stmt argument to sqlite3_stmt_busy in all the whizing around): def interrupt_function(db, stmt, timeout, whizround) while whizround and !sqlite3_stmt_busy(stmt) /* whizround waiting for statement to start */ sleep(0.001)

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Keith Medcalf
On Monday, 31 December, 2018 13:48, Simon Slavin wrote: >On 31 Dec 2018, at 8:18pm, Jesse Rittner wrote: >> I'm trying to write a function to run a query with a timeout. If >> the timeout expires, the query must stop execution within a "reasonable" >> amount >> of time. >There is no rule

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Keith Medcalf
On Monday, 31 December, 2018 13:19, Jesse Rittner wrote: >Keith Medcalf wrote >> What are you trying to accomplish? Perhaps what you really want is >> a progress callback? > I'm trying to write a function to run a query with a timeout. If the > timeout expires, the query must stop execution

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Jesse Rittner
Simon Slavin-3 wrote > You can calculate an "end time" yourself, check it each time you're ready > to call sqlite3_step(), and jump straight to sqlite3_finalize() if your > time is up. I'm not familiar with the inner workings of sqlite3_step, but if that itself takes time, then I'd like to

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Simon Slavin
On 31 Dec 2018, at 8:18pm, Jesse Rittner wrote: > I'm trying to write a function to run a query with a timeout. If the timeout > expires, the query must stop execution within a "reasonable" amount of time. There is no rule that you must continue to call sqlite3_step() until it runs out of

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Jesse Rittner
Keith Medcalf wrote > What are you trying to accomplish? Perhaps what you really want is a > progress callback? I'm trying to write a function to run a query with a timeout. If the timeout expires, the query must stop execution within a "reasonable" amount of time. To use a progress callback, it

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Keith Medcalf
>To be clear, is it sqlite3_step returning SQLITE_DONE that marks it >as "not running", or calling sqlite3_reset/sqlite3_finalize? Well, "running" means that execution has commenced (the first call to sqlite3_step has been made on the statement) and the execution has not yet completed.

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Jesse Rittner
To be clear, is it sqlite3_step returning SQLITE_DONE that marks it as "not running", or calling sqlite3_reset/sqlite3_finalize? Also, is there any way to mark a statement as "running" other than calling sqlite_step on it? Otherwise, it sounds like I'll have to wait until after sqlite3_step gets

Re: [sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Keith Medcalf
"RUNNING" means that the statement is running. When you call sqlite3_prepare, SQLite3 generates a PROGRAM which will "yield" the results of the execution of that SQL statement. It looks something like this: START: ... do stuff ... LOOP: ... do stuff ... return a result row (SQLITE_ROW)

[sqlite] Using sqlite3_interrupt with a timeout

2018-12-31 Thread Jesse Rittner
Consider the following pseudo-code. void interrupt_timeout(sqlite3* db, int timeout) { sleep(timeout); sqlite3_interrupt(db); } int main() { sqlite3* db = sqlite3_open_v2(...); sqlite3_stmt* stmt = sqlite3_prepare_v2(db, ...); ... pthread_create(interrupt_timeout, db,

Re: [sqlite] Thread-Safety of Multi-Thread Connection

2018-12-31 Thread Richard Hipp
On 12/31/18, Jesse Rittner wrote: > I have some questions about multi-thread (as opposed to serialized, see > https://www.sqlite.org/threadsafe.html) connections. > > 1. If I have two multi-thread connections that are using a shared cache, is > it safe to use those two connections concurrently

[sqlite] Thread-Safety of Multi-Thread Connection

2018-12-31 Thread Jesse Rittner
I have some questions about multi-thread (as opposed to serialized, see https://www.sqlite.org/threadsafe.html) connections. 1. If I have two multi-thread connections that are using a shared cache, is it safe to use those two connections concurrently with each other? 2. Same as (1), but what if

Re: [sqlite] Shared Cache vs. Serialized

2018-12-31 Thread Jesse Rittner
Keith Medcalf wrote > See also Write Ahead Logging journal mode (WAL) where in the case you > specified B's operation will succeed even if it is updating a table being > read by connection A. Oh, good to know! For anyone who stumbles across this thread in the future, note that this requires that

Re: [sqlite] Bug in 3.25.2 (RECURSIVE CTE + window function)

2018-12-31 Thread Dan Kennedy
On 12/30/2018 02:41 PM, Nicolas Roy-Renaud wrote: I've been dealing with occasional segfaults on one of my applications when running a similar query, except even on SQLite 3.26, the safeguard wouldn't trigger. Running the SQL query specified in the bug report description from the tracker