diff --git a/Userland/Libraries/LibSQL/AST/Statement.cpp b/Userland/Libraries/LibSQL/AST/Statement.cpp index fc3cd34087..7bc718d3ac 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 55a8af7dac..8d915c4aa5 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() {