diff options
Diffstat (limited to 'odb/mysql/connection.cxx')
-rw-r--r-- | odb/mysql/connection.cxx | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx index 7679e27..98fd427 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/error.hxx> #include <odb/mysql/exceptions.hxx> #include <odb/mysql/statement-cache.hxx> @@ -66,6 +67,31 @@ namespace odb mysql_close (handle_); } + bool connection:: + ping () + { + if (failed ()) + return false; + + if (!mysql_ping (handle_)) + return true; + + switch (mysql_errno (handle_)) + { + case CR_SERVER_LOST: + case CR_SERVER_GONE_ERROR: + { + mark_failed (); + return false; + } + default: + { + translate_error (*this); + return false; // Never reached. + } + } + } + MYSQL_STMT* connection:: alloc_stmt_handle () { |