diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2011-02-21 12:47:58 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2011-02-21 12:47:58 +0200 |
commit | 9155251867692cb212c26fd5380abc0815c2f44b (patch) | |
tree | e3c342a806f2164e8c50ee39d619ae36a9a4dfdc | |
parent | 495ec10e4c1880e1d6cce5526a4d6a43a48bfa94 (diff) |
Factor out active statement cancelling into separate function
-rw-r--r-- | odb/mysql/connection-factory.cxx | 2 | ||||
-rw-r--r-- | odb/mysql/connection.cxx | 7 | ||||
-rw-r--r-- | odb/mysql/connection.hxx | 12 | ||||
-rw-r--r-- | odb/mysql/database.cxx | 2 | ||||
-rw-r--r-- | odb/mysql/statement.cxx | 24 | ||||
-rw-r--r-- | odb/mysql/transaction-impl.cxx | 7 |
6 files changed, 33 insertions, 21 deletions
diff --git a/odb/mysql/connection-factory.cxx b/odb/mysql/connection-factory.cxx index 2f1b00c..2d86b82 100644 --- a/odb/mysql/connection-factory.cxx +++ b/odb/mysql/connection-factory.cxx @@ -229,7 +229,9 @@ namespace odb void connection_pool_factory:: release (pooled_connection* c) { + c->clear (); c->pool_ = 0; + lock l (mutex_); // Determine if we need to keep or free this connection. diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx index 98fd427..cfdd26c 100644 --- a/odb/mysql/connection.cxx +++ b/odb/mysql/connection.cxx @@ -8,6 +8,7 @@ #include <odb/mysql/database.hxx> #include <odb/mysql/connection.hxx> +#include <odb/mysql/statement.hxx> #include <odb/mysql/error.hxx> #include <odb/mysql/exceptions.hxx> #include <odb/mysql/statement-cache.hxx> @@ -92,6 +93,12 @@ namespace odb } } + void connection:: + clear_ () + { + active_->cancel (); // Should clear itself from active_. + } + MYSQL_STMT* connection:: alloc_stmt_handle () { diff --git a/odb/mysql/connection.hxx b/odb/mysql/connection.hxx index 16d3438..89103c7 100644 --- a/odb/mysql/connection.hxx +++ b/odb/mysql/connection.hxx @@ -94,6 +94,15 @@ namespace odb free_stmt_handles (); } + // Cancel and clear the active statement, if any. + // + void + clear () + { + if (active_ != 0) + clear_ (); + } + public: MYSQL_STMT* alloc_stmt_handle (); @@ -109,6 +118,9 @@ namespace odb void free_stmt_handles (); + void + clear_ (); + private: database_type& db_; bool failed_; diff --git a/odb/mysql/database.cxx b/odb/mysql/database.cxx index 72b18d8..31d6c7b 100644 --- a/odb/mysql/database.cxx +++ b/odb/mysql/database.cxx @@ -218,6 +218,8 @@ namespace odb throw not_in_transaction (); connection_type& c (transaction::current ().connection ()); + c.clear (); + MYSQL* h (c.handle ()); if (mysql_real_query (h, s, static_cast<unsigned long> (n))) diff --git a/odb/mysql/statement.cxx b/odb/mysql/statement.cxx index 7ab9c04..b311dbe 100644 --- a/odb/mysql/statement.cxx +++ b/odb/mysql/statement.cxx @@ -68,8 +68,7 @@ namespace odb data_ (data), data_version_ (0) { - if (statement* a = conn_.active ()) - a->cancel (); + conn_.clear (); if (mysql_stmt_prepare (stmt_, s.c_str (), s.size ()) != 0) translate_error (conn_, stmt_); @@ -78,8 +77,7 @@ namespace odb void select_statement:: execute () { - if (statement* a = conn_.active ()) - a->cancel (); + conn_.clear (); if (cached_) free_result (); @@ -230,8 +228,7 @@ namespace odb insert_statement (connection& conn, const string& s, binding& data) : statement (conn), data_ (data), data_version_ (0) { - if (statement* a = conn_.active ()) - a->cancel (); + conn_.clear (); if (mysql_stmt_prepare (stmt_, s.c_str (), s.size ()) != 0) translate_error (conn_, stmt_); @@ -240,8 +237,7 @@ namespace odb bool insert_statement:: execute () { - if (statement* a = conn_.active ()) - a->cancel (); + conn_.clear (); if (mysql_stmt_reset (stmt_)) translate_error (conn_, stmt_); @@ -284,8 +280,7 @@ namespace odb image_ (image), image_version_ (0) { - if (statement* a = conn_.active ()) - a->cancel (); + conn_.clear (); if (mysql_stmt_prepare (stmt_, s.c_str (), s.size ()) != 0) translate_error (conn_, stmt_); @@ -294,8 +289,7 @@ namespace odb void update_statement:: execute () { - if (statement* a = conn_.active ()) - a->cancel (); + conn_.clear (); if (mysql_stmt_reset (stmt_)) translate_error (conn_, stmt_); @@ -338,8 +332,7 @@ namespace odb delete_statement (connection& conn, const string& s, binding& cond) : statement (conn), cond_ (cond), cond_version_ (0) { - if (statement* a = conn_.active ()) - a->cancel (); + conn_.clear (); if (mysql_stmt_prepare (stmt_, s.c_str (), s.size ()) != 0) translate_error (conn_, stmt_); @@ -348,8 +341,7 @@ namespace odb unsigned long long delete_statement:: execute () { - if (statement* a = conn_.active ()) - a->cancel (); + conn_.clear (); if (mysql_stmt_reset (stmt_)) translate_error (conn_, stmt_); diff --git a/odb/mysql/transaction-impl.cxx b/odb/mysql/transaction-impl.cxx index b523568..659dc56 100644 --- a/odb/mysql/transaction-impl.cxx +++ b/odb/mysql/transaction-impl.cxx @@ -6,7 +6,6 @@ #include <odb/mysql/mysql.hxx> #include <odb/mysql/database.hxx> #include <odb/mysql/connection.hxx> -#include <odb/mysql/statement.hxx> #include <odb/mysql/error.hxx> #include <odb/mysql/transaction-impl.hxx> @@ -30,8 +29,7 @@ namespace odb void transaction_impl:: commit () { - if (statement* a = connection_->active ()) - a->cancel (); + connection_->clear (); if (mysql_real_query (connection_->handle (), "commit", 6) != 0) translate_error (*connection_); @@ -44,8 +42,7 @@ namespace odb void transaction_impl:: rollback () { - if (statement* a = connection_->active ()) - a->cancel (); + connection_->clear (); if (mysql_real_query (connection_->handle (), "rollback", 8) != 0) translate_error (*connection_); |