mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-03 17:27:47 +00:00
Fixed mysql autoreconnect for prepared statements
This commit is contained in:
parent
bc9d33724a
commit
8574e92559
2 changed files with 15 additions and 4 deletions
|
@ -61,7 +61,7 @@ uint32_t Core::Db::DbConnection::open()
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_pConnection = base->connect( m_connectionInfo.host, m_connectionInfo.user, m_connectionInfo.password,
|
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 );
|
m_pConnection->setSchema( m_connectionInfo.database );
|
||||||
}
|
}
|
||||||
|
@ -79,9 +79,9 @@ uint32_t Core::Db::DbConnection::getLastError()
|
||||||
return m_pConnection->getErrorNo();
|
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()
|
bool Core::Db::DbConnection::lockIfReady()
|
||||||
|
@ -146,6 +146,17 @@ boost::shared_ptr< Mysql::ResultSet > Core::Db::DbConnection::query( boost::shar
|
||||||
if( !stmt )
|
if( !stmt )
|
||||||
return nullptr;
|
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();
|
uint32_t index = stmt->getIndex();
|
||||||
|
|
||||||
auto pStmt = getPreparedStatement( index );
|
auto pStmt = getPreparedStatement( index );
|
||||||
|
|
|
@ -72,7 +72,7 @@ namespace Db
|
||||||
void rollbackTransaction();
|
void rollbackTransaction();
|
||||||
void commitTransaction();
|
void commitTransaction();
|
||||||
|
|
||||||
void ping();
|
bool ping();
|
||||||
|
|
||||||
uint32_t getLastError();
|
uint32_t getLastError();
|
||||||
bool lockIfReady();
|
bool lockIfReady();
|
||||||
|
|
Loading…
Add table
Reference in a new issue