Index: src/libchcore/TSQLiteTransaction.cpp =================================================================== diff -u -N -rb1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0 -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 --- src/libchcore/TSQLiteTransaction.cpp (.../TSQLiteTransaction.cpp) (revision b1ecc12ba4c1f2a7b4acd6e82fc4193535e55ff0) +++ src/libchcore/TSQLiteTransaction.cpp (.../TSQLiteTransaction.cpp) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) @@ -22,80 +22,79 @@ #include "ErrorCodes.h" #include "sqlite3/sqlite3.h" -BEGIN_CHCORE_NAMESPACE - -namespace sqlite +namespace chcore { - TSQLiteTransaction::TSQLiteTransaction(const TSQLiteDatabasePtr& spDatabase) : - m_spDatabase(spDatabase), - m_bTransactionStarted(false) + namespace sqlite { - if(!m_spDatabase) - THROW_SQLITE_EXCEPTION(eErr_InvalidArgument, 0, _T("Invalid database provided")); - Begin(); - } + TSQLiteTransaction::TSQLiteTransaction(const TSQLiteDatabasePtr& spDatabase) : + m_spDatabase(spDatabase), + m_bTransactionStarted(false) + { + if (!m_spDatabase) + THROW_SQLITE_EXCEPTION(eErr_InvalidArgument, 0, _T("Invalid database provided")); + Begin(); + } - TSQLiteTransaction::~TSQLiteTransaction() - { - // try to rollback the transaction; this is the last resort - if(m_bTransactionStarted && m_spDatabase->GetInTransaction()) + TSQLiteTransaction::~TSQLiteTransaction() { - int iResult = sqlite3_exec((sqlite3*)m_spDatabase->GetHandle(), "ROLLBACK TRANSACTION;", NULL, NULL, NULL); - iResult; - _ASSERTE(iResult == SQLITE_OK); - m_spDatabase->SetInTransaction(false); + // try to rollback the transaction; this is the last resort + if (m_bTransactionStarted && m_spDatabase->GetInTransaction()) + { + int iResult = sqlite3_exec((sqlite3*)m_spDatabase->GetHandle(), "ROLLBACK TRANSACTION;", NULL, NULL, NULL); + iResult; + _ASSERTE(iResult == SQLITE_OK); + m_spDatabase->SetInTransaction(false); + } } - } - void TSQLiteTransaction::Begin() - { - if(m_spDatabase->GetInTransaction()) - return; + void TSQLiteTransaction::Begin() + { + if (m_spDatabase->GetInTransaction()) + return; - if(m_bTransactionStarted) - THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotBeginTransaction, 0, _T("Transaction already started")); + if (m_bTransactionStarted) + THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotBeginTransaction, 0, _T("Transaction already started")); - int iResult = sqlite3_exec((sqlite3*)m_spDatabase->GetHandle(), "BEGIN TRANSACTION", NULL, NULL, NULL); - if(iResult != SQLITE_OK) - THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotBeginTransaction, iResult, _T("Cannot begin transaction")); + int iResult = sqlite3_exec((sqlite3*)m_spDatabase->GetHandle(), "BEGIN TRANSACTION", NULL, NULL, NULL); + if (iResult != SQLITE_OK) + THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotBeginTransaction, iResult, _T("Cannot begin transaction")); - m_spDatabase->SetInTransaction(true); - m_bTransactionStarted = true; - } + m_spDatabase->SetInTransaction(true); + m_bTransactionStarted = true; + } - void TSQLiteTransaction::Rollback() - { - // no transactions whatsoever (even on database) - if(!m_bTransactionStarted && !m_spDatabase->GetInTransaction()) - THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotRollbackTransaction, 0, _T("Transaction not started")); + void TSQLiteTransaction::Rollback() + { + // no transactions whatsoever (even on database) + if (!m_bTransactionStarted && !m_spDatabase->GetInTransaction()) + THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotRollbackTransaction, 0, _T("Transaction not started")); - // database has transaction started, but not by this object - if(!m_bTransactionStarted) - return; + // database has transaction started, but not by this object + if (!m_bTransactionStarted) + return; - int iResult = sqlite3_exec((sqlite3*)m_spDatabase->GetHandle(), "ROLLBACK TRANSACTION;", NULL, NULL, NULL); - if(iResult != SQLITE_OK) - THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotRollbackTransaction, iResult, _T("Cannot rollback transaction")); - m_spDatabase->SetInTransaction(false); - m_bTransactionStarted = false; - } + int iResult = sqlite3_exec((sqlite3*)m_spDatabase->GetHandle(), "ROLLBACK TRANSACTION;", NULL, NULL, NULL); + if (iResult != SQLITE_OK) + THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotRollbackTransaction, iResult, _T("Cannot rollback transaction")); + m_spDatabase->SetInTransaction(false); + m_bTransactionStarted = false; + } - void TSQLiteTransaction::Commit() - { - // no transactions whatsoever (even on database) - if(!m_bTransactionStarted && !m_spDatabase->GetInTransaction()) - THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotRollbackTransaction, 0, _T("Transaction not started")); + void TSQLiteTransaction::Commit() + { + // no transactions whatsoever (even on database) + if (!m_bTransactionStarted && !m_spDatabase->GetInTransaction()) + THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotRollbackTransaction, 0, _T("Transaction not started")); - // database has transaction started, but not by this object - if(!m_bTransactionStarted) - return; + // database has transaction started, but not by this object + if (!m_bTransactionStarted) + return; - int iResult = sqlite3_exec((sqlite3*)m_spDatabase->GetHandle(), "COMMIT TRANSACTION;", NULL, NULL, NULL); - if(iResult != SQLITE_OK) - THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotCommitTransaction, iResult, _T("Cannot commit transaction")); - m_spDatabase->SetInTransaction(false); - m_bTransactionStarted = false; + int iResult = sqlite3_exec((sqlite3*)m_spDatabase->GetHandle(), "COMMIT TRANSACTION;", NULL, NULL, NULL); + if (iResult != SQLITE_OK) + THROW_SQLITE_EXCEPTION(eErr_SQLiteCannotCommitTransaction, iResult, _T("Cannot commit transaction")); + m_spDatabase->SetInTransaction(false); + m_bTransactionStarted = false; + } } } - -END_CHCORE_NAMESPACE