diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-09 18:14:37 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-09 18:14:37 +0200 |
commit | 2bf2944a844d002267d3508ce81a2128ccbb8af7 (patch) | |
tree | 32732629cdd48b789242e6a8dc1673c593f6fb8f /odb/sqlite/connection.cxx | |
parent | 857fabab0c537a286e8a39503bf987029669d854 (diff) |
Make database class move-constructible
This means it can be returned by value from a function in C++11.
Diffstat (limited to 'odb/sqlite/connection.cxx')
-rw-r--r-- | odb/sqlite/connection.cxx | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/odb/sqlite/connection.cxx b/odb/sqlite/connection.cxx index c44d648..b150470 100644 --- a/odb/sqlite/connection.cxx +++ b/odb/sqlite/connection.cxx @@ -29,12 +29,13 @@ namespace odb namespace sqlite { connection:: - connection (database_type& db, int extra_flags) - : odb::connection (db), - db_ (db), + connection (connection_factory& cf, int extra_flags) + : odb::connection (cf), unlock_cond_ (unlock_mutex_), active_objects_ (0) { + database_type& db (database ()); + int f (db.flags () | extra_flags); const string& n (db.name ()); @@ -81,9 +82,8 @@ namespace odb } connection:: - connection (database_type& db, sqlite3* handle) - : odb::connection (db), - db_ (db), + connection (connection_factory& cf, sqlite3* handle) + : odb::connection (cf), handle_ (handle), unlock_cond_ (unlock_mutex_), active_objects_ (0) @@ -94,14 +94,16 @@ namespace odb void connection:: init () { + database_type& db (database ()); + // Enable/disable foreign key constraints. // generic_statement st ( *this, - db_.foreign_keys () + db.foreign_keys () ? "PRAGMA foreign_keys=ON" : "PRAGMA foreign_keys=OFF", - db_.foreign_keys () ? 22 : 23); + db.foreign_keys () ? 22 : 23); st.execute (); // Create statement cache. @@ -190,6 +192,20 @@ namespace odb while (active_objects_ != 0) active_objects_->clear (); } + + // connection_factory + // + connection_factory:: + ~connection_factory () + { + } + + void connection_factory:: + database (database_type& db) + { + odb::connection_factory::db_ = &db; + db_ = &db; + } } } |