Discussion:
[soci-users] SQLite lock access errors
JP
2013-11-08 17:13:39 UTC
Permalink
Hi all,

I'm using a SQLite database, and in my application I have with several
threads reading/writing. Sometimes I get errors accessing the database,
probably because one thread tries to read while another is writing. I can
handle this situation using a mutex. However, there is also an external
application that works with the same database, and I can not synchronize
the access in any way between that application and mine. What surprises me
is that I thought SQLite had a kind of time-out, around 5 seconds, before
aborting the operation, if there are access problems, but the SOCI methods
abort the operation instantly, isn't there any time-out? or re-try the
operation a number of times?

Thanks a lot in advance.
JP
Felix Krause
2013-11-11 12:25:42 UTC
Permalink
Post by JP
Hi all,
I'm using a SQLite database, and in my application I have with several
threads reading/writing. Sometimes I get errors accessing the database,
probably because one thread tries to read while another is writing. I can
handle this situation using a mutex. However, there is also an external
application that works with the same database, and I can not synchronize
the access in any way between that application and mine. What surprises me
is that I thought SQLite had a kind of time-out, around 5 seconds, before
aborting the operation, if there are access problems, but the SOCI methods
abort the operation instantly, isn't there any time-out? or re-try the
operation a number of times?
You can set the timeout like this (assuming sql is a soci::session):

soci::sqlite3_session_backend * sessionBackEnd =
static_cast<soci::sqlite3_session_backend *>(sql.get_backend());
sqlite_api::sqlite3_busy_timeout(sessionBackEnd->conn_, 1000);

This will set the timeout to 1 second for your session.

Regards,
Felix
JP
2013-11-12 02:23:42 UTC
Permalink
Hi Felix,

I've seen that, actually, a time-out of 1 secs. is already set in the
backend of SQLite, within th source.cpp. But, this is very strange, because
that this time-out is not used at all when I get the errors; I'd say that
the time-out is zero, when there is another process reading the database,
and I try to make an "insert" query, the SOCI throws an exception without
any time-out...

Thanks.
JP
Post by Felix Krause
Post by JP
Hi all,
I'm using a SQLite database, and in my application I have with several
threads reading/writing. Sometimes I get errors accessing the database,
probably because one thread tries to read while another is writing. I can
handle this situation using a mutex. However, there is also an external
application that works with the same database, and I can not synchronize
the access in any way between that application and mine. What surprises me
is that I thought SQLite had a kind of time-out, around 5 seconds, before
aborting the operation, if there are access problems, but the SOCI methods
abort the operation instantly, isn't there any time-out? or re-try the
operation a number of times?
soci::sqlite3_session_backend * sessionBackEnd =
static_cast<soci::sqlite3_session_backend *>(sql.get_backend());
sqlite_api::sqlite3_busy_timeout(sessionBackEnd->conn_, 1000);
This will set the timeout to 1 second for your session.
Regards,
Felix
------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models.
Explore
techniques for threading, error checking, porting, and tuning. Get the most
from the latest Intel processors and coprocessors. See abstracts and
register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
soci-users mailing list
https://lists.sourceforge.net/lists/listinfo/soci-users
Loading...