Reorganizing the directory, the sources and the msvc files

This commit is contained in:
Sebastien Rombauts
2013-03-10 12:18:47 +01:00
parent 7c25eff6ff
commit 1a82510821
24 changed files with 49 additions and 57 deletions

58
src/Transaction.cpp Normal file
View File

@@ -0,0 +1,58 @@
/**
* @file Transaction.cpp
* @brief A Transaction is way to group multiple SQL statements into an atomic secured operation.
*
* Copyright (c) 2012-2013 Sebastien Rombauts (sebastien.rombauts@gmail.com)
*
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
* or copy at http://opensource.org/licenses/MIT)
*/
#include "Transaction.h"
#include "Database.h"
namespace SQLite
{
// Begins the SQLite transaction
Transaction::Transaction(Database& aDatabase) : // throw(SQLite::Exception)
mDatabase(aDatabase),
mbCommited(false)
{
mDatabase.exec("BEGIN");
}
// Safely rollback the transaction if it has not been committed.
Transaction::~Transaction(void) throw() // nothrow
{
if (false == mbCommited)
{
try
{
mDatabase.exec("ROLLBACK");
}
catch (SQLite::Exception& /*e*/)
{
// Never throw an exception in a destructor
//std::cout << e.what() << std::endl;
SQLITE_CPP_ASSERT(false);
}
}
}
// Commit the transaction.
void Transaction::commit(void) // throw(SQLite::Exception)
{
if (false == mbCommited)
{
mDatabase.exec("COMMIT");
mbCommited = true;
}
else
{
throw SQLite::Exception("Transaction already commited");
}
}
} // namespace SQLite