Page MenuHomePhabricator

D5291.diff
No OneTemporary

D5291.diff

diff --git a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
--- a/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
+++ b/native/cpp/CommonCpp/DatabaseManagers/SQLiteQueryExecutor.cpp
@@ -637,6 +637,10 @@
auto rc = applyMigration(db);
if (!rc) {
+ if (shouldBeInTransaction) {
+ sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr);
+ }
+
migration_msg << "migration " << idx << " failed." << std::endl;
Logger::log(migration_msg.str());
break;
@@ -646,7 +650,20 @@
update_version << "PRAGMA user_version=" << idx << ";";
auto update_version_str = update_version.str();
- sqlite3_exec(db, update_version_str.c_str(), nullptr, nullptr, nullptr);
+ char *error;
+ sqlite3_exec(db, update_version_str.c_str(), nullptr, nullptr, &error);
+ if (error && shouldBeInTransaction) {
+ sqlite3_exec(db, "ROLLBACK;", nullptr, nullptr, nullptr);
+ }
+ if (error) {
+ std::ostringstream errorStream;
+ errorStream << "Error updating database version after migration " << idx
+ << ": " << error;
+ Logger::log(errorStream.str());
+ sqlite3_free(error);
+
+ break;
+ }
if (shouldBeInTransaction) {
sqlite3_exec(db, "END TRANSACTION;", nullptr, nullptr, nullptr);

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 15, 11:31 PM (21 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2495775
Default Alt Text
D5291.diff (1 KB)

Event Timeline