aboutsummaryrefslogtreecommitdiff
path: root/odb/mysql/connection.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2011-02-21 12:06:03 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2011-02-21 12:06:03 +0200
commit81c2f16a9826d92cf5b54da71f70943263878d3e (patch)
treee71b970490eca51a515e4d1f259e543f20b68bb9 /odb/mysql/connection.cxx
parent6c85f1a50e3b50d18599143e18ee145fc6afdb08 (diff)
Validate connection in MySQL pool factory
This will help deal with the MySQL server closing connections after a certain period of inactivity.
Diffstat (limited to 'odb/mysql/connection.cxx')
-rw-r--r--odb/mysql/connection.cxx26
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 ()
{