SQLite Forum

Is there a way to wait until the database is available?
Login

Is there a way to wait until the database is available?

(1) By 6kEs4Majrd on 2020-06-03 22:09:12 [link] [source]

There is busy_timeout. But it must be a finite number. Is there a way to let sqlite3 wait until the database is available? Thanks.

pragma busy_timeout=10000;

(2) By Richard Hipp (drh) on 2020-06-03 22:15:07 in reply to 1 [source]

The "busy_timeout" is implemented as an sqlite3_busy_handler() callback. You can substitute a different callback to do whatever you want.

(5) By 6kEs4Majrd on 2020-06-03 23:33:04 in reply to 2 [link] [source]

Could you show the code that should be used at the SQL command level instead of the C level? Thanks.

(6) By Stephan Beal (stephan) on 2020-06-03 23:37:18 in reply to 5 [link] [source]

Could you show the code that should be used at the SQL command level instead of the C level?

The pragma is the only way to do it without from the console app. Setting it to the highest signed 32-bit value, like in your response to my deleted (and inaccurate) response, is the closest you can get with that app without writing and loading a custom C extension.

(3.1) By Stephan Beal (stephan) on 2020-06-03 22:17:15 edited from 3.0 in reply to 1 [link] [source]

Deleted

(4) By 6kEs4Majrd on 2020-06-03 23:31:53 in reply to 3.1 [link] [source]

The max signed 32 bit integer is 2147483647. So I should set it as the following?

pragma busy_timeout=2147483647;

(7) By Gunter Hick (gunter_hick) on 2020-06-04 06:17:31 in reply to 1 [link] [source]

Wrong question. As you explained in your other post, you are expecting a deadlock to occur. By definition, no amount of waiting will resolve a deadlock. (At least) one of the processes involved in the deadlock has to release the resources it has acquired and start over. The proper response to SQLITE_BUSY as an indication of deadlock is to ROLLBACK and then repeat the transaction.