aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/sqlite/connection.cxx10
-rw-r--r--odb/sqlite/database.cxx9
-rw-r--r--odb/sqlite/database.hxx9
3 files changed, 26 insertions, 2 deletions
diff --git a/odb/sqlite/connection.cxx b/odb/sqlite/connection.cxx
index d90c301..ffb70a7 100644
--- a/odb/sqlite/connection.cxx
+++ b/odb/sqlite/connection.cxx
@@ -66,6 +66,16 @@ namespace odb
translate_error (e, *this);
}
+ // Enable/disable foreign key constraints.
+ //
+ simple_statement st (
+ *this,
+ db.foreign_keys ()
+ ? "PRAGMA foreign_keys=ON"
+ : "PRAGMA foreign_keys=OFF",
+ db.foreign_keys () ? 22 : 23);
+ st.execute ();
+
statement_cache_.reset (new statement_cache_type (*this));
}
diff --git a/odb/sqlite/database.cxx b/odb/sqlite/database.cxx
index e756608..6ce4621 100644
--- a/odb/sqlite/database.cxx
+++ b/odb/sqlite/database.cxx
@@ -27,8 +27,12 @@ namespace odb
database::
database (const string& name,
int flags,
+ bool foreign_keys,
auto_ptr<connection_factory> factory)
- : name_ (name), flags_ (flags), factory_ (factory)
+ : name_ (name),
+ flags_ (flags),
+ foreign_keys_ (foreign_keys),
+ factory_ (factory)
{
if (factory_.get () == 0)
factory_.reset (new connection_pool_factory ());
@@ -41,8 +45,9 @@ namespace odb
char* argv[],
bool erase,
int flags,
+ bool foreign_keys,
std::auto_ptr<connection_factory> factory)
- : flags_ (flags), factory_ (factory)
+ : flags_ (flags), foreign_keys_ (foreign_keys), factory_ (factory)
{
using namespace details;
diff --git a/odb/sqlite/database.hxx b/odb/sqlite/database.hxx
index 0eadbbf..13c44e6 100644
--- a/odb/sqlite/database.hxx
+++ b/odb/sqlite/database.hxx
@@ -35,6 +35,7 @@ namespace odb
public:
database (const std::string& name,
int flags = SQLITE_OPEN_READWRITE,
+ bool foreign_keys = true,
std::auto_ptr<connection_factory> =
std::auto_ptr<connection_factory> (0));
@@ -56,6 +57,7 @@ namespace odb
char* argv[],
bool erase = false,
int flags = SQLITE_OPEN_READWRITE,
+ bool foreign_keys = true,
std::auto_ptr<connection_factory> =
std::auto_ptr<connection_factory> (0));
@@ -76,6 +78,12 @@ namespace odb
return flags_;
}
+ bool
+ foreign_keys () const
+ {
+ return foreign_keys_;
+ }
+
// Transactions.
//
public:
@@ -103,6 +111,7 @@ namespace odb
private:
std::string name_;
int flags_;
+ bool foreign_keys_;
std::auto_ptr<connection_factory> factory_;
};
}