1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 08:27:46 +00:00

Added transactions

This commit is contained in:
Mordred 2017-09-19 23:12:46 +02:00
parent 1031d66522
commit ee73eedc85

View file

@ -15,9 +15,7 @@ Core::Db::Connection::Connection( MySqlBase * pBase,
m_pRawCon = mysql_init( nullptr ); m_pRawCon = mysql_init( nullptr );
if( mysql_real_connect( m_pRawCon, hostName.c_str(), userName.c_str(), password.c_str(), if( mysql_real_connect( m_pRawCon, hostName.c_str(), userName.c_str(), password.c_str(),
nullptr, 3306, nullptr, 0) == nullptr ) nullptr, 3306, nullptr, 0) == nullptr )
{
throw std::runtime_error( mysql_error( m_pRawCon ) ); throw std::runtime_error( mysql_error( m_pRawCon ) );
}
m_bConnected = true; m_bConnected = true;
} }
@ -103,9 +101,7 @@ Core::Db::Connection::Connection( MySqlBase * pBase,
if( mysql_real_connect( m_pRawCon, hostName.c_str(), userName.c_str(), password.c_str(), if( mysql_real_connect( m_pRawCon, hostName.c_str(), userName.c_str(), password.c_str(),
nullptr, 3306, nullptr, 0) == nullptr ) nullptr, 3306, nullptr, 0) == nullptr )
{
throw std::runtime_error( mysql_error( m_pRawCon ) ); throw std::runtime_error( mysql_error( m_pRawCon ) );
}
} }
@ -180,17 +176,20 @@ bool Core::Db::Connection::getAutoCommit()
void Core::Db::Connection::beginTransaction() void Core::Db::Connection::beginTransaction()
{ {
boost::scoped_ptr< Statement > stmt( createStatement() );
stmt->execute( "START TRANSACTION;" );
} }
void Core::Db::Connection::commitTransaction() void Core::Db::Connection::commitTransaction()
{ {
boost::scoped_ptr< Statement > stmt( createStatement() );
stmt->execute( "COMMIT" );
} }
void Core::Db::Connection::rollbackTransaction() void Core::Db::Connection::rollbackTransaction()
{ {
boost::scoped_ptr< Statement > stmt( createStatement() );
stmt->execute( "ROLLBACK" );
} }
std::string Core::Db::Connection::escapeString( const std::string &inData ) std::string Core::Db::Connection::escapeString( const std::string &inData )