aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/statement.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-03-29 16:31:59 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-03-29 16:31:59 +0200
commit7aadac132d8512e7ee63970561f40ade80772726 (patch)
tree001695ad14cd9c2e6937a8e5d45a32587d0a37d5 /odb/sqlite/statement.cxx
parent2cdc08a9bcf807b4b908434c7bbe5439b0da3191 (diff)
Support for shared cache and unlock notification
Diffstat (limited to 'odb/sqlite/statement.cxx')
-rw-r--r--odb/sqlite/statement.cxx75
1 files changed, 63 insertions, 12 deletions
diff --git a/odb/sqlite/statement.cxx b/odb/sqlite/statement.cxx
index 0975545..f503144 100644
--- a/odb/sqlite/statement.cxx
+++ b/odb/sqlite/statement.cxx
@@ -30,16 +30,19 @@ namespace odb
void statement::
init (const char* s, std::size_t n)
{
- if (int e = sqlite3_prepare_v2 (
- conn_.handle (),
- s,
- static_cast<int> (n),
- &stmt_,
- 0))
+ int e;
+ while ((e = sqlite3_prepare_v2 (conn_.handle (),
+ s,
+ static_cast<int> (n),
+ &stmt_,
+ 0)) == SQLITE_LOCKED)
{
- translate_error (e, conn_);
+ conn_.wait ();
}
+ if (e != SQLITE_OK)
+ translate_error (e, conn_);
+
active_ = false;
cached_ = false;
@@ -194,8 +197,20 @@ namespace odb
unsigned long long r (0);
+ // Only the first call to sqlite3_step() can return SQLITE_LOCKED.
+ //
int e;
- for (e = sqlite3_step (stmt_); e == SQLITE_ROW; e = sqlite3_step (stmt_))
+ sqlite3* h (conn_.handle ());
+ while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
+ {
+ if (sqlite3_extended_errcode (h) != SQLITE_LOCKED_SHAREDCACHE)
+ break;
+
+ sqlite3_reset (stmt_);
+ conn_.wait ();
+ }
+
+ for (; e == SQLITE_ROW; e = sqlite3_step (stmt_))
r++;
sqlite3_reset (stmt_);
@@ -245,7 +260,16 @@ namespace odb
{
if (!done_)
{
- int e (sqlite3_step (stmt_));
+ int e;
+ sqlite3* h (conn_.handle ());
+ while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
+ {
+ if (sqlite3_extended_errcode (h) != SQLITE_LOCKED_SHAREDCACHE)
+ break;
+
+ sqlite3_reset (stmt_);
+ conn_.wait ();
+ }
if (e != SQLITE_ROW)
{
@@ -292,7 +316,16 @@ namespace odb
{
bind_param (data_.bind, data_.count);
- int e (sqlite3_step (stmt_));
+ int e;
+ sqlite3* h (conn_.handle ());
+ while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
+ {
+ if (sqlite3_extended_errcode (h) != SQLITE_LOCKED_SHAREDCACHE)
+ break;
+
+ sqlite3_reset (stmt_);
+ conn_.wait ();
+ }
sqlite3_reset (stmt_);
@@ -337,7 +370,16 @@ namespace odb
bind_param (data_.bind, data_.count);
bind_param (cond_.bind, cond_.count, data_.count);
- int e (sqlite3_step (stmt_));
+ int e;
+ sqlite3* h (conn_.handle ());
+ while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
+ {
+ if (sqlite3_extended_errcode (h) != SQLITE_LOCKED_SHAREDCACHE)
+ break;
+
+ sqlite3_reset (stmt_);
+ conn_.wait ();
+ }
sqlite3_reset (stmt_);
@@ -362,7 +404,16 @@ namespace odb
{
bind_param (cond_.bind, cond_.count);
- int e (sqlite3_step (stmt_));
+ int e;
+ sqlite3* h (conn_.handle ());
+ while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
+ {
+ if (sqlite3_extended_errcode (h) != SQLITE_LOCKED_SHAREDCACHE)
+ break;
+
+ sqlite3_reset (stmt_);
+ conn_.wait ();
+ }
sqlite3_reset (stmt_);