mirror of
https://github.com/open-goal/jak-project
synced 2026-06-23 17:35:19 -04:00
bf83f2442d
- Rough start of the SQLite integration to facilitate the SQL queries - Cleanup and disable a little bit of code so the game no longer crashes when entering the editor - Implement some of the mouse data stuff  https://user-images.githubusercontent.com/13153231/202881484-399747e7-dcdb-4e09-93e9-b561a45c8a18.mp4 This is a very old branch so best to get it merged now that it's at a decent point so it can be iterated on.
82 lines
1.9 KiB
C++
Vendored
Generated
82 lines
1.9 KiB
C++
Vendored
Generated
/**
|
|
* @file Transaction.cpp
|
|
* @ingroup SQLiteCpp
|
|
* @brief A Transaction is way to group multiple SQL statements into an atomic secured operation.
|
|
*
|
|
* Copyright (c) 2012-2022 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 <SQLiteCpp/Transaction.h>
|
|
|
|
#include <SQLiteCpp/Database.h>
|
|
#include <SQLiteCpp/Assertion.h>
|
|
|
|
#include <sqlite3.h>
|
|
|
|
namespace SQLite
|
|
{
|
|
|
|
|
|
// Begins the SQLite transaction
|
|
Transaction::Transaction(Database& aDatabase, TransactionBehavior behavior) :
|
|
mDatabase(aDatabase)
|
|
{
|
|
const char *stmt;
|
|
switch (behavior) {
|
|
case TransactionBehavior::DEFERRED:
|
|
stmt = "BEGIN DEFERRED";
|
|
break;
|
|
case TransactionBehavior::IMMEDIATE:
|
|
stmt = "BEGIN IMMEDIATE";
|
|
break;
|
|
case TransactionBehavior::EXCLUSIVE:
|
|
stmt = "BEGIN EXCLUSIVE";
|
|
break;
|
|
default:
|
|
throw SQLite::Exception("invalid/unknown transaction behavior", SQLITE_ERROR);
|
|
}
|
|
mDatabase.exec(stmt);
|
|
}
|
|
|
|
// Begins the SQLite transaction
|
|
Transaction::Transaction(Database &aDatabase) :
|
|
mDatabase(aDatabase)
|
|
{
|
|
mDatabase.exec("BEGIN");
|
|
}
|
|
|
|
// Safely rollback the transaction if it has not been committed.
|
|
Transaction::~Transaction()
|
|
{
|
|
if (false == mbCommited)
|
|
{
|
|
try
|
|
{
|
|
mDatabase.exec("ROLLBACK");
|
|
}
|
|
catch (SQLite::Exception&)
|
|
{
|
|
// Never throw an exception in a destructor: error if already rollbacked, but no harm is caused by this.
|
|
}
|
|
}
|
|
}
|
|
|
|
// Commit the transaction.
|
|
void Transaction::commit()
|
|
{
|
|
if (false == mbCommited)
|
|
{
|
|
mDatabase.exec("COMMIT");
|
|
mbCommited = true;
|
|
}
|
|
else
|
|
{
|
|
throw SQLite::Exception("Transaction already committed.");
|
|
}
|
|
}
|
|
|
|
|
|
} // namespace SQLite
|