# HG changeset patch # User František Kučera # Date 1577205417 -3600 # Node ID ec793cb3e686a474736a6c8b83c287ca1f696510 # Parent 884ece10575d338d6353117698d26a601fc4894c rename DB methods to match standard API diff -r 884ece10575d -r ec793cb3e686 src/SqlHandler.h --- a/src/SqlHandler.h Sat Dec 14 14:00:36 2019 +0100 +++ b/src/SqlHandler.h Tue Dec 24 17:36:57 2019 +0100 @@ -135,6 +135,11 @@ class Connection { private: sqlite3* db; + + void begin() { + sqlite3_exec(db, "BEGIN", nullptr, nullptr, nullptr); + } + public: Connection(const char* filename) { @@ -143,6 +148,7 @@ sqlite3_close(db); throw SqlException(L"Unable to open SQLite database."); } + begin(); } virtual ~Connection() { @@ -157,15 +163,21 @@ else throw SqlException(L"Unable to prepare SQLite statement."); } - void transactionBegin() { - sqlite3_exec(db, "BEGIN", nullptr, nullptr, nullptr); + bool getAutoCommit() { + return sqlite3_get_autocommit(db); } - void transactionCommit() { + void setAutoCommit(bool autoCommit) { + bool autoCommitOld = getAutoCommit(); + if (autoCommit && !autoCommitOld) commit(); + else if (!autoCommit && autoCommitOld) begin(); + } + + void commit() { sqlite3_exec(db, "COMMIT", nullptr, nullptr, nullptr); } - void transactionRollback() { + void rollback() { sqlite3_exec(db, "ROLLBACK", nullptr, nullptr, nullptr); } @@ -287,7 +299,7 @@ } connection.reset(new Connection(file.c_str())); - connection->transactionBegin(); + connection->setAutoCommit(false); } virtual ~SqlHandler() { @@ -376,7 +388,7 @@ // pass-through some relations: for (const CopyRelations& copy : configuration.copyRelations) copyRelations(copy); - connection->transactionCommit(); + connection->commit(); // delete or keep the file: if (configuration.file.size()) {