From ee73eedc85e3231675dc19d0ba04a0dd5f318ae1 Mon Sep 17 00:00:00 2001 From: Mordred Date: Tue, 19 Sep 2017 23:12:46 +0200 Subject: [PATCH] Added transactions --- src/servers/Server_Common/Database/Connection.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/servers/Server_Common/Database/Connection.cpp b/src/servers/Server_Common/Database/Connection.cpp index c59277c6..c8a799df 100644 --- a/src/servers/Server_Common/Database/Connection.cpp +++ b/src/servers/Server_Common/Database/Connection.cpp @@ -15,9 +15,7 @@ Core::Db::Connection::Connection( MySqlBase * pBase, m_pRawCon = mysql_init( nullptr ); if( mysql_real_connect( m_pRawCon, hostName.c_str(), userName.c_str(), password.c_str(), nullptr, 3306, nullptr, 0) == nullptr ) - { throw std::runtime_error( mysql_error( m_pRawCon ) ); - } 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(), nullptr, 3306, nullptr, 0) == nullptr ) - { throw std::runtime_error( mysql_error( m_pRawCon ) ); - } } @@ -180,17 +176,20 @@ bool Core::Db::Connection::getAutoCommit() void Core::Db::Connection::beginTransaction() { - + boost::scoped_ptr< Statement > stmt( createStatement() ); + stmt->execute( "START TRANSACTION;" ); } void Core::Db::Connection::commitTransaction() { - + boost::scoped_ptr< Statement > stmt( createStatement() ); + stmt->execute( "COMMIT" ); } void Core::Db::Connection::rollbackTransaction() { - + boost::scoped_ptr< Statement > stmt( createStatement() ); + stmt->execute( "ROLLBACK" ); } std::string Core::Db::Connection::escapeString( const std::string &inData )