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 | 34087db5762e86dcc60e596c70522303a623051c (patch) | |
tree | 76e7ad1c7356ba92fefd7c9ba424d31b035d37cd /odb/mysql/connection.cxx | |
parent | fcd2821109dd056b46494c3f71e5a015e2c08736 (diff) |
Make database class move-constructible
This means it can be returned by value from a function in C++11.
Diffstat (limited to 'odb/mysql/connection.cxx')
-rw-r--r-- | odb/mysql/connection.cxx | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx index 4b57287..11bbc83 100644 --- a/odb/mysql/connection.cxx +++ b/odb/mysql/connection.cxx @@ -20,21 +20,20 @@ namespace odb namespace mysql { connection:: - connection (database_type& db) - : odb::connection (db), - db_ (db), - failed_ (false), - active_ (0) + connection (connection_factory& cf) + : odb::connection (cf), failed_ (false), active_ (0) { if (mysql_init (&mysql_) == 0) throw bad_alloc (); handle_.reset (&mysql_); - if (*db_.charset () != '\0') + database_type& db (database ()); + + if (*db.charset () != '\0') // Can only fail if we pass an unknown option. // - mysql_options (handle_, MYSQL_SET_CHARSET_NAME, db_.charset ()); + mysql_options (handle_, MYSQL_SET_CHARSET_NAME, db.charset ()); // Force the CLIENT_FOUND_ROWS flag so that UPDATE returns the // number of found rows, not the number of changed rows. This @@ -68,9 +67,8 @@ namespace odb } connection:: - connection (database_type& db, MYSQL* handle) - : odb::connection (db), - db_ (db), + connection (connection_factory& cf, MYSQL* handle) + : odb::connection (cf), failed_ (false), handle_ (handle), active_ (0), @@ -203,5 +201,19 @@ namespace odb stmt_handles_.clear (); } + + // connection_factory + // + connection_factory:: + ~connection_factory () + { + } + + void connection_factory:: + database (database_type& db) + { + odb::connection_factory::db_ = &db; + db_ = &db; + } } } |