|
|
Question : Ruby and SQLite3: How To Force Busy Exception
|
|
Hello,
I have a Ruby application that uses SQLite3 (with sqlite3-ruby). Sometimes it crashes with a SQLite3::BusyException. I think I could fix this with a begin...rescue...end block, but first I need to know how to guarantee a crash.
Is there any way to lock a sqlite3 database and not release the lock until it is released explicitly?
I've tried an execute_batch statement, with a lot of updates, but apparently the lock is released between each statement in the batch, because usually it crashes while the original program is fine.
Thanks in advance,
s1m0ne
|
Answer : Ruby and SQLite3: How To Force Busy Exception
|
|
Here's the page on locking: http://www.sqlite.org/lockingv3.html
If you use BEGIN, you can get exclusive access to the database: http://www.sqlite.org/lang_transaction.html
BEGIN EXCLUSIVE # database writing COMMIT
"An EXCLUSIVE lock is needed in order to write to the database file. Only one EXCLUSIVE lock is allowed on the file and no other locks of any kind are allowed to coexist with an EXCLUSIVE lock. "
Seems like you could put that into a ruby begin ... rescue block to catch the thrown exception if the database is locked.
|
|
|
|
|