diff options
-rw-r--r-- | odb/mysql/connection-factory.cxx | 7 | ||||
-rw-r--r-- | odb/mysql/connection.cxx | 1 | ||||
-rw-r--r-- | odb/mysql/connection.hxx | 14 | ||||
-rw-r--r-- | odb/mysql/error.cxx | 11 |
4 files changed, 29 insertions, 4 deletions
diff --git a/odb/mysql/connection-factory.cxx b/odb/mysql/connection-factory.cxx index dce0f97..b9b3d19 100644 --- a/odb/mysql/connection-factory.cxx +++ b/odb/mysql/connection-factory.cxx @@ -230,9 +230,10 @@ namespace odb // Determine if we need to keep or free this connection. // - bool keep (waiters_ != 0 || - min_ == 0 || - (connections_.size () + in_use_ <= min_)); + bool keep (!c->failed () && + (waiters_ != 0 || + min_ == 0 || + (connections_.size () + in_use_ <= min_))); in_use_--; diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx index 1395592..7679e27 100644 --- a/odb/mysql/connection.cxx +++ b/odb/mysql/connection.cxx @@ -20,6 +20,7 @@ namespace odb connection:: connection (database_type& db) : db_ (db), + failed_ (false), handle_ (&mysql_), active_ (0), statement_cache_ (new statement_cache_type (*this)) diff --git a/odb/mysql/connection.hxx b/odb/mysql/connection.hxx index 0310ee6..6704f23 100644 --- a/odb/mysql/connection.hxx +++ b/odb/mysql/connection.hxx @@ -46,6 +46,19 @@ namespace odb } public: + bool + failed () const + { + return failed_; + } + + void + mark_failed () + { + failed_ = true; + } + + public: MYSQL* handle () { @@ -91,6 +104,7 @@ namespace odb private: database_type& db_; + bool failed_; MYSQL mysql_; MYSQL* handle_; diff --git a/odb/mysql/error.cxx b/odb/mysql/error.cxx index 460816a..94a41b2 100644 --- a/odb/mysql/error.cxx +++ b/odb/mysql/error.cxx @@ -16,7 +16,7 @@ namespace odb namespace mysql { void - translate_error (connection&, + translate_error (connection& c, unsigned int e, const std::string& sqlstate, const std::string& message) @@ -31,6 +31,15 @@ namespace odb { throw deadlock (); } + case CR_SERVER_LOST: + case CR_SERVER_GONE_ERROR: + case CR_UNKNOWN_ERROR: + { + // This connection is no longer usable. + // + c.mark_failed (); + // Fall through. + } default: { throw database_exception (e, sqlstate, message); |