1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-03 09:17:47 +00:00

Fixed mysql autoreconnect for prepared statements

This commit is contained in:
Mordred 2018-01-16 16:36:24 +01:00
parent bc9d33724a
commit 8574e92559
2 changed files with 15 additions and 4 deletions

View file

@ -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 );

View file

@ -72,7 +72,7 @@ namespace Db
void rollbackTransaction();
void commitTransaction();
void ping();
bool ping();
uint32_t getLastError();
bool lockIfReady();