void SqLiteDataProvider::rollbackTransaction() throw (std::runtime_error) { if (!mIsConnected) { const std::string error = "Trying to rollback a transaction while not " "connected to the database!"; LOG_ERROR(error); throw std::runtime_error(error); } if (!inTransaction()) { const std::string error = "Trying to rollback a transaction while no " "one is open!"; LOG_ERROR(error); throw std::runtime_error(error); } // trying to rollback a transaction try { execSql("ROLLBACK TRANSACTION;"); LOG_DEBUG("SQL: transaction rolled back"); } catch (const DbSqlQueryExecFailure &e) { std::ostringstream error; error << "SQL ERROR while trying to rollback a transaction: " << e.what(); LOG_ERROR(error); throw std::runtime_error(error.str()); } }
void MySqlDataProvider::rollbackTransaction() throw (std::runtime_error) { if (!mIsConnected) { const std::string error = "Trying to rollback a transaction while not " "connected to the database!"; LOG_ERROR(error); throw std::runtime_error(error); } if (!inTransaction()) { const std::string error = "Trying to rollback a transaction while no " "one is open!"; LOG_ERROR(error); throw std::runtime_error(error); } if (mysql_rollback(mDb) != 0) { LOG_ERROR("MySqlDataProvider::rollbackTransaction: " << mysql_error(mDb)); throw DbSqlQueryExecFailure(mysql_error(mDb)); } mysql_autocommit(mDb, AUTOCOMMIT_ON); mInTransaction = false; LOG_DEBUG("SQL: transaction rolled back"); }
void SqLiteDataProvider::beginTransaction() throw (std::runtime_error) { if (!mIsConnected) { const std::string error = "Trying to begin a transaction while not " "connected to the database!"; LOG_ERROR(error); throw std::runtime_error(error); } if (inTransaction()) { const std::string error = "Trying to begin a transaction while anoter " "one is still open!"; LOG_ERROR(error); throw std::runtime_error(error); } // trying to open a transaction try { execSql("BEGIN TRANSACTION;"); LOG_DEBUG("SQL: started transaction"); } catch (const DbSqlQueryExecFailure &e) { std::ostringstream error; error << "SQL ERROR while trying to start a transaction: " << e.what(); LOG_ERROR(error); throw std::runtime_error(error.str()); } }
void MySqlDataProvider::beginTransaction() throw (std::runtime_error) { if (!mIsConnected) { const std::string error = "Trying to begin a transaction while not " "connected to the database!"; LOG_ERROR(error); throw std::runtime_error(error); } if (inTransaction()) { const std::string error = "Trying to begin a transaction while another " "one is still open!"; LOG_ERROR(error); throw std::runtime_error(error); } if (mysql_autocommit(mDb, AUTOCOMMIT_OFF)) { const std::string error = "Error while trying to disable autocommit"; LOG_ERROR(error); throw std::runtime_error(error); } mInTransaction = true; execSql("BEGIN"); LOG_DEBUG("SQL: started transaction"); }