Re: [Vala] shared access to sqlite database
- From: Jim Nelson <jim yorba org>
- To: Evan Nemerson <evan coeus-group com>
- Cc: vala-list <vala-list gnome org>
- Subject: Re: [Vala] shared access to sqlite database
- Date: Wed, 07 Aug 2013 18:57:01 -0007
To chime in some agreement, we attempted many strategies to parallelize
transactions and work around SQLite's locking issues in Geary before
finally waving the white flag. Evan's correct, SQLite's built-in busy
handler is what you want to use. In fact, we use a single background
thread to service all calls, as the busy handler isn't entirely fair
when multiple threads contend for the lock.
-- Jim
On Wed, Aug 7, 2013 at 12:33 AM, Evan Nemerson <evan coeus-group com>
wrote:
On Wed, 2013-08-07 at 08:16 +0200, David López González wrote:
Hi everyone,
I need to access to a single data base with diferent processes, and
eventually, I always get an access error "Error: 5, database is
locked".
A simplified code which reproduce the problem it's presented below.
Take a look at [1]. I know unlock notify isn't what you're after
(since
you have multiple processes, not multiple threads), but IIRC it should
give you a pretty good feel for sqlite does.
Really, the only option is to just retry the operation. You can do
this
automatically using sqlite3_busy_timeout ([2]). It is bound as
Sqlite.Database.busy_timeout.
There is also sqlite3_busy_handler ([3])... I don't think it's bound
in
Vala at the moment, but it would be trivial to add it to the bindings
(or just use the extern keyword). Theoretically you could use it to
iterate through the main loop or something while you wait, but it's a
lot simpler to just use busy_timeout and interact with sqlite in a
thread if you really need to.
-E
[1] https://sqlite.org/unlock_notify.html
[2] https://sqlite.org/c3ref/busy_timeout.html
[3] https://sqlite.org/c3ref/busy_handler.html
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]