Specify SELECT timeout for SQLITE

Is it possible to specify the maximum period of time that a SELECT query can execute using SQLITE?

The situation will be useful where you have large tables, and users should be able to enter free search terms. If the search for the terms found is not quickly found, the entire table is scanned, which can take a very long time, since indexes can usually not be used.

So, if SQLITE crashes after a few seconds, it will be useful.

I am using SQLITE through System.Data.Sqlite, and it seemed that SqliteCommand.CommandTimeout would be what I want, but tuning apparently has no effect for any reason. Maybe I missed something.

+6
source share
1 answer

For a simple select query, there seems to be no way to set a timeout or maximum runtime on SQLite itself. The only mention of a timeout in the documentation is the busy timeout . Thus, if you need to limit the maximum period of time that a selection request can select, you will need to associate your connection with a timeout at the application level and cancel / close your connection if this timeout is exceeded. How to do this will obviously be application / language specific.

For a busy timeout (the timeout before the connection stops waiting for the lock to clear), you can do this through the provided C interface or using the SQLite driver provided to your application.

+1
source

Source: https://habr.com/ru/post/903123/


All Articles