From 17988bab7518658f66c649b540a7d4b795f13fd5 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 27 Oct 2022 09:06:13 -0400 Subject: [PATCH] LibSQL: Immediately commit database modifications (for now) This ensures tables survive the database connection quitting. LibSQL does not have transactional sessions yet, and probably won't for a while, so let's just commit each modification as it comes. --- Userland/Libraries/LibSQL/AST/Statement.cpp | 7 ++++++- Userland/Libraries/LibSQL/Database.cpp | 12 +----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Userland/Libraries/LibSQL/AST/Statement.cpp b/Userland/Libraries/LibSQL/AST/Statement.cpp index fc3cd340875..7bc718d3acc 100644 --- a/Userland/Libraries/LibSQL/AST/Statement.cpp +++ b/Userland/Libraries/LibSQL/AST/Statement.cpp @@ -14,7 +14,12 @@ namespace SQL::AST { ResultOr Statement::execute(AK::NonnullRefPtr database) const { ExecutionContext context { move(database), this, nullptr }; - return execute(context); + auto result = TRY(execute(context)); + + // FIXME: When transactional sessions are supported, don't auto-commit modifications. + TRY(context.database->commit()); + + return result; } } diff --git a/Userland/Libraries/LibSQL/Database.cpp b/Userland/Libraries/LibSQL/Database.cpp index 55a8af7dac4..8d915c4aa5f 100644 --- a/Userland/Libraries/LibSQL/Database.cpp +++ b/Userland/Libraries/LibSQL/Database.cpp @@ -66,17 +66,7 @@ ErrorOr Database::open() return {}; } -Database::~Database() -{ - // This crashes if the database can't commit. It's recommended to commit - // before the Database goes out of scope so the application can handle - // errors. - // Maybe we should enforce that by having a VERIFY here that there are no - // pending writes. But that's a new API on Heap so let's not do that right - // now. - if (is_open()) - MUST(commit()); -} +Database::~Database() = default; ErrorOr Database::commit() {