diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-08-10 13:57:24 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-08-10 13:57:24 +0200 |
commit | b49d3e5e0e58e69b4fde856e37f73d101b5b2c0a (patch) | |
tree | 92c587949496e21028071ab7ca2202bc5b67f6bb /odb/mysql/connection.cxx | |
parent | 0a589394a09ce5b3f16d902d657710a2886cc2fc (diff) |
Delay closing statement until there are no active statements
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 (); + } } } |