From 7aadac132d8512e7ee63970561f40ade80772726 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 29 Mar 2011 16:31:59 +0200 Subject: Support for shared cache and unlock notification --- odb/sqlite/statement.cxx | 75 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 12 deletions(-) (limited to 'odb/sqlite/statement.cxx') 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 (n), - &stmt_, - 0)) + int e; + while ((e = sqlite3_prepare_v2 (conn_.handle (), + s, + static_cast (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_); -- cgit v1.1