diff options
Diffstat (limited to 'odb/mysql/connection.cxx')
-rw-r--r-- | odb/mysql/connection.cxx | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx index 7eb1b34..c6ca5a3 100644 --- a/odb/mysql/connection.cxx +++ b/odb/mysql/connection.cxx @@ -9,6 +9,8 @@ #include <odb/mysql/connection.hxx> #include <odb/mysql/exceptions.hxx> +using namespace std; + namespace odb { namespace mysql @@ -18,7 +20,7 @@ namespace odb : handle_ (&mysql_), active_ (0), statement_cache_ (*this) { if (mysql_init (handle_) == 0) - throw std::bad_alloc (); + throw bad_alloc (); // Force the CLIENT_FOUND_ROWS flag so that UPDATE returns the // number of found rows, not the number of changed rows. This @@ -43,7 +45,42 @@ namespace odb connection:: ~connection () { + if (stmt_handles_.size () > 0) + free_stmt_handles (); + mysql_close (handle_); } + + MYSQL_STMT* connection:: + alloc_stmt_handle () + { + MYSQL_STMT* stmt (mysql_stmt_init (handle_)); + + if (stmt == 0) + throw bad_alloc (); + + return stmt; + } + + void connection:: + free_stmt_handle (MYSQL_STMT* stmt) + { + if (active_ == 0) + mysql_stmt_close (stmt); + else + stmt_handles_.push_back (stmt); + } + + void connection:: + free_stmt_handles () + { + for (stmt_handles::iterator i (stmt_handles_.begin ()), + e (stmt_handles_.end ()); i != e; ++i) + { + mysql_stmt_close (*i); + } + + stmt_handles_.clear (); + } } } |