From 55c4420b69fa172ac7b6b3523597b9a46a5d1bcd Mon Sep 17 00:00:00 2001 From: rtk0c Date: Sun, 22 May 2022 14:54:06 -0700 Subject: Vendor SQLiteCpp completely for internal patching --- 3rdparty/sqlitecpp/source/SQLiteCpp/Savepoint.cpp | 65 +++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 3rdparty/sqlitecpp/source/SQLiteCpp/Savepoint.cpp (limited to '3rdparty/sqlitecpp/source/SQLiteCpp/Savepoint.cpp') diff --git a/3rdparty/sqlitecpp/source/SQLiteCpp/Savepoint.cpp b/3rdparty/sqlitecpp/source/SQLiteCpp/Savepoint.cpp new file mode 100644 index 0000000..b3d13a2 --- /dev/null +++ b/3rdparty/sqlitecpp/source/SQLiteCpp/Savepoint.cpp @@ -0,0 +1,65 @@ +/** + * @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) + * + * Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or + * copy at http://opensource.org/licenses/MIT) + */ + +#include +#include +#include +#include + +namespace SQLite { + +// Begins the SQLite savepoint +Savepoint::Savepoint(Database& aDatabase, std::string aName) + : mDatabase(aDatabase), msName(aName), mbReleased(false) { + // 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 -- cgit v1.2.3-70-g09d2