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 --- .../sqlitecpp/source/SQLiteCpp/Transaction.cpp | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 3rdparty/sqlitecpp/source/SQLiteCpp/Transaction.cpp (limited to '3rdparty/sqlitecpp/source/SQLiteCpp/Transaction.cpp') diff --git a/3rdparty/sqlitecpp/source/SQLiteCpp/Transaction.cpp b/3rdparty/sqlitecpp/source/SQLiteCpp/Transaction.cpp new file mode 100644 index 0000000..2a8857a --- /dev/null +++ b/3rdparty/sqlitecpp/source/SQLiteCpp/Transaction.cpp @@ -0,0 +1,83 @@ +/** + * @file Transaction.cpp + * @ingroup SQLiteCpp + * @brief A Transaction is way to group multiple SQL statements into an atomic secured operation. + * + * Copyright (c) 2012-2019 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 + +#include +#include + +#include + +namespace SQLite +{ + + +// Begins the SQLite transaction +Transaction::Transaction(Database& aDatabase, TransactionBehavior behavior) : + mDatabase(aDatabase), + mbCommited(false) +{ + 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), + mbCommited(false) +{ + 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 -- cgit v1.2.3-70-g09d2