From 1c2289c99f86a9f8cccfa87aef981e7c39dd4e9e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 28 Aug 2011 16:07:38 +0200 Subject: Add support for creating connection from existing handle This will allow for custom connection establishment and configuration. --- odb/mysql/connection.cxx | 16 ++++++++++++++-- odb/mysql/connection.hxx | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx index f8e88a0..e8c9903 100644 --- a/odb/mysql/connection.cxx +++ b/odb/mysql/connection.cxx @@ -26,8 +26,7 @@ namespace odb db_ (db), failed_ (false), handle_ (&mysql_), - active_ (0), - statement_cache_ (new statement_cache_type (*this)) + active_ (0) { if (mysql_init (handle_) == 0) throw bad_alloc (); @@ -64,6 +63,19 @@ namespace odb throw database_exception (e, sqlstate, message); } + + statement_cache_.reset (new statement_cache_type (*this)); + } + + connection:: + connection (database_type& db, MYSQL* handle) + : odb::connection (db), + db_ (db), + failed_ (false), + handle_ (handle), + active_ (0) + { + statement_cache_.reset (new statement_cache_type (*this)); } connection:: diff --git a/odb/mysql/connection.hxx b/odb/mysql/connection.hxx index ab0692d..f4462ed 100644 --- a/odb/mysql/connection.hxx +++ b/odb/mysql/connection.hxx @@ -43,6 +43,7 @@ namespace odb ~connection (); connection (database_type&); + connection (database_type&, MYSQL* handle); database_type& database () -- cgit v1.1