diff --git a/src/common/Database/DbConnection.cpp b/src/common/Database/DbConnection.cpp index b0633492..b33fbbd2 100644 --- a/src/common/Database/DbConnection.cpp +++ b/src/common/Database/DbConnection.cpp @@ -61,7 +61,7 @@ uint32_t Core::Db::DbConnection::open() try { m_pConnection = base->connect( m_connectionInfo.host, m_connectionInfo.user, m_connectionInfo.password, - options, m_connectionInfo.port ); + options, m_connectionInfo.port ); m_pConnection->setSchema( m_connectionInfo.database ); } @@ -79,9 +79,9 @@ uint32_t Core::Db::DbConnection::getLastError() return m_pConnection->getErrorNo(); } -void Core::Db::DbConnection::ping() +bool Core::Db::DbConnection::ping() { - m_pConnection->ping(); + return m_pConnection->ping(); } bool Core::Db::DbConnection::lockIfReady() @@ -146,6 +146,17 @@ boost::shared_ptr< Mysql::ResultSet > Core::Db::DbConnection::query( boost::shar if( !stmt ) return nullptr; + if( !ping() ) + { + g_log.error( "MysqlConnection went down" ); + // naivly reconnect and hope for the best + open(); + lockIfReady(); + if( !prepareStatements() ) + g_log.error( "Mysql Statements failed to prepare..." ); + g_log.info( "MysqlConnection reestablished" ); + } + uint32_t index = stmt->getIndex(); auto pStmt = getPreparedStatement( index ); diff --git a/src/common/Database/DbConnection.h b/src/common/Database/DbConnection.h index ddb66e17..f304e423 100644 --- a/src/common/Database/DbConnection.h +++ b/src/common/Database/DbConnection.h @@ -72,7 +72,7 @@ namespace Db void rollbackTransaction(); void commitTransaction(); - void ping(); + bool ping(); uint32_t getLastError(); bool lockIfReady();