Files
jak-project/third-party/SQLiteCpp/src/Savepoint.cpp
T
Tyler Wilding bf83f2442d d/jak2: cleanup more of editable and editable-player (#2029)
- 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


![image](https://user-images.githubusercontent.com/13153231/202881481-95bc0a2a-ac3d-4f65-aff1-b9f7ee5ee345.png)


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.
2022-11-19 23:28:20 -05:00

67 lines
2.0 KiB
C++
Vendored
Generated

/**
* @file Savepoint.cpp
* @ingroup SQLiteCpp
* @brief A Savepoint is a way to group multiple SQL statements into an atomic
* secured operation. Similar to a transaction while allowing child savepoints.
*
* Copyright (c) 2020 Kelvin Hammond (hammond.kelvin@gmail.com)
* Copyright (c) 2020-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/Assertion.h>
#include <SQLiteCpp/Database.h>
#include <SQLiteCpp/Savepoint.h>
#include <SQLiteCpp/Statement.h>
namespace SQLite {
// Begins the SQLite savepoint
Savepoint::Savepoint(Database& aDatabase, const std::string& aName)
: mDatabase(aDatabase), msName(aName) {
// workaround because you cannot bind to SAVEPOINT
// escape name for use in query
Statement stmt(mDatabase, "SELECT quote(?)");
stmt.bind(1, msName);
stmt.executeStep();
msName = stmt.getColumn(0).getText();
mDatabase.exec(std::string("SAVEPOINT ") + msName);
}
// Safely rollback the savepoint if it has not been committed.
Savepoint::~Savepoint() {
if (!mbReleased) {
try {
rollback();
} catch (SQLite::Exception&) {
// Never throw an exception in a destructor: error if already rolled
// back or released, but no harm is caused by this.
}
}
}
// Release the savepoint and commit
void Savepoint::release() {
if (!mbReleased) {
mDatabase.exec(std::string("RELEASE SAVEPOINT ") + msName);
mbReleased = true;
} else {
throw SQLite::Exception("Savepoint already released or rolled back.");
}
}
// Rollback the savepoint
void Savepoint::rollback() {
if (!mbReleased) {
mDatabase.exec(std::string("ROLLBACK TO SAVEPOINT ") + msName);
mbReleased = true;
} else {
throw SQLite::Exception("Savepoint already released or rolled back.");
}
}
} // namespace SQLite