aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite
diff options
context:
space:
mode:
Diffstat (limited to 'odb/sqlite')
-rw-r--r--odb/sqlite/connection-factory.cxx6
-rw-r--r--odb/sqlite/connection.cxx2
-rw-r--r--odb/sqlite/error.cxx14
-rw-r--r--odb/sqlite/makefile6
-rw-r--r--odb/sqlite/statement.cxx40
5 files changed, 58 insertions, 10 deletions
diff --git a/odb/sqlite/connection-factory.cxx b/odb/sqlite/connection-factory.cxx
index 75f1240..63d7507 100644
--- a/odb/sqlite/connection-factory.cxx
+++ b/odb/sqlite/connection-factory.cxx
@@ -7,6 +7,8 @@
#include <odb/sqlite/database.hxx>
#include <odb/sqlite/connection-factory.hxx>
+#include <odb/sqlite/details/config.hxx> // LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
+
using namespace std;
namespace odb
@@ -117,8 +119,10 @@ namespace odb
// Unless explicitly disabled, enable shared cache.
//
+#ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
if ((db_->flags () & SQLITE_OPEN_PRIVATECACHE) == 0)
extra_flags_ |= SQLITE_OPEN_SHAREDCACHE;
+#endif
}
//
@@ -190,8 +194,10 @@ namespace odb
// Unless explicitly disabled, enable shared cache.
//
+#ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
if ((db_->flags () & SQLITE_OPEN_PRIVATECACHE) == 0)
extra_flags_ |= SQLITE_OPEN_SHAREDCACHE;
+#endif
if (min_ > 0)
{
diff --git a/odb/sqlite/connection.cxx b/odb/sqlite/connection.cxx
index 22955b4..a477e28 100644
--- a/odb/sqlite/connection.cxx
+++ b/odb/sqlite/connection.cxx
@@ -45,8 +45,10 @@ namespace odb
// A connection can only be used by a single thread at a time. So
// disable locking in SQLite unless explicitly requested.
//
+#if defined(SQLITE_OPEN_NOMUTEX)
if ((f & SQLITE_OPEN_FULLMUTEX) == 0)
f |= SQLITE_OPEN_NOMUTEX;
+#endif
const string& vfs (db.vfs ());
diff --git a/odb/sqlite/error.cxx b/odb/sqlite/error.cxx
index b7d56c1..847e9c1 100644
--- a/odb/sqlite/error.cxx
+++ b/odb/sqlite/error.cxx
@@ -10,6 +10,8 @@
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/exceptions.hxx>
+#include <odb/sqlite/details/config.hxx> // LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
+
using namespace std;
namespace odb
@@ -20,7 +22,14 @@ namespace odb
translate_error (int e, connection& c)
{
sqlite3* h (c.handle ());
+
+ // Extended error codes are only available in 3.6.5 and later.
+ //
+#if SQLITE_VERSION_NUMBER >= 3006005
int ee (sqlite3_extended_errcode (h));
+#else
+ int ee (0);
+#endif
string m;
switch (e)
@@ -40,9 +49,10 @@ namespace odb
}
case SQLITE_LOCKED:
{
+#ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
if (ee != SQLITE_LOCKED_SHAREDCACHE)
throw deadlock (); // The DROP TABLE special case.
-
+#endif
// Getting SQLITE_LOCKED_SHAREDCACHE here means we don't have
// the unlock notify support. Translate this to timeout.
//
@@ -51,8 +61,10 @@ namespace odb
case SQLITE_BUSY:
case SQLITE_IOERR:
{
+#if SQLITE_VERSION_NUMBER >= 3006005
if (e != SQLITE_IOERR || ee == SQLITE_IOERR_BLOCKED)
throw timeout ();
+#endif
// Fall throught.
}
diff --git a/odb/sqlite/makefile b/odb/sqlite/makefile
index a1e8c17..28cb2fe 100644
--- a/odb/sqlite/makefile
+++ b/odb/sqlite/makefile
@@ -75,7 +75,11 @@ $(out_base)/details/config.h: | $(out_base)/details/.
@echo '#ifndef ODB_SQLITE_DETAILS_CONFIG_H' >>$@
@echo '#define ODB_SQLITE_DETAILS_CONFIG_H' >>$@
@echo '' >>$@
- @echo '#define LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY 1' >>$@
+ @echo '#include <sqlite3.h>' >>$@
+ @echo '' >>$@
+ @echo '#if SQLITE_VERSION_NUMBER >= 3006012' >>$@
+ @echo ' #define LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY 1' >>$@
+ @echo '#endif' >>$@
@echo '' >>$@
@echo '#endif /* ODB_SQLITE_DETAILS_CONFIG_H */' >>$@
diff --git a/odb/sqlite/statement.cxx b/odb/sqlite/statement.cxx
index 36066ff..e1731ac 100644
--- a/odb/sqlite/statement.cxx
+++ b/odb/sqlite/statement.cxx
@@ -10,6 +10,8 @@
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/error.hxx>
+#include <odb/sqlite/details/config.hxx> // LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
+
using namespace std;
namespace odb
@@ -281,10 +283,12 @@ namespace odb
unsigned long long r (0);
- // Only the first call to sqlite3_step() can return SQLITE_LOCKED.
- //
int e;
sqlite3* h (conn_.handle ());
+
+#ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
+ // Only the first call to sqlite3_step() can return SQLITE_LOCKED.
+ //
while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
{
if (sqlite3_extended_errcode (h) != SQLITE_LOCKED_SHAREDCACHE)
@@ -293,6 +297,9 @@ namespace odb
sqlite3_reset (stmt_);
conn_.wait ();
}
+#else
+ e = sqlite3_step (stmt_);
+#endif
for (; e == SQLITE_ROW; e = sqlite3_step (stmt_))
r++;
@@ -303,8 +310,7 @@ namespace odb
translate_error (e, conn_);
if (!result_set_)
- r = static_cast<unsigned long long> (
- sqlite3_changes (conn_.handle ()));
+ r = static_cast<unsigned long long> (sqlite3_changes (h));
return r;
}
@@ -377,6 +383,8 @@ namespace odb
if (!done_)
{
int e;
+
+#ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
sqlite3* h (conn_.handle ());
while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
{
@@ -386,6 +394,9 @@ namespace odb
sqlite3_reset (stmt_);
conn_.wait ();
}
+#else
+ e = sqlite3_step (stmt_);
+#endif
if (e != SQLITE_ROW)
{
@@ -447,6 +458,8 @@ namespace odb
bind_param (param_.bind, param_.count);
int e;
+
+#ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
sqlite3* h (conn_.handle ());
while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
{
@@ -456,6 +469,9 @@ namespace odb
sqlite3_reset (stmt_);
conn_.wait ();
}
+#else
+ e = sqlite3_step (stmt_);
+#endif
sqlite3_reset (stmt_);
@@ -512,6 +528,8 @@ namespace odb
int e;
sqlite3* h (conn_.handle ());
+
+#ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
{
if (sqlite3_extended_errcode (h) != SQLITE_LOCKED_SHAREDCACHE)
@@ -520,14 +538,16 @@ namespace odb
sqlite3_reset (stmt_);
conn_.wait ();
}
+#else
+ e = sqlite3_step (stmt_);
+#endif
sqlite3_reset (stmt_);
if (e != SQLITE_DONE)
translate_error (e, conn_);
- return static_cast<unsigned long long> (
- sqlite3_changes (conn_.handle ()));
+ return static_cast<unsigned long long> (sqlite3_changes (h));
}
// delete_statement
@@ -560,6 +580,8 @@ namespace odb
int e;
sqlite3* h (conn_.handle ());
+
+#ifdef LIBODB_SQLITE_HAVE_UNLOCK_NOTIFY
while ((e = sqlite3_step (stmt_)) == SQLITE_LOCKED)
{
if (sqlite3_extended_errcode (h) != SQLITE_LOCKED_SHAREDCACHE)
@@ -568,14 +590,16 @@ namespace odb
sqlite3_reset (stmt_);
conn_.wait ();
}
+#else
+ e = sqlite3_step (stmt_);
+#endif
sqlite3_reset (stmt_);
if (e != SQLITE_DONE)
translate_error (e, conn_);
- return static_cast<unsigned long long> (
- sqlite3_changes (conn_.handle ()));
+ return static_cast<unsigned long long> (sqlite3_changes (h));
}
}
}