From a4a795af333d6bcf378e11df456a858af2fa4603 Mon Sep 17 00:00:00 2001 From: Marvin W Date: Sun, 15 Dec 2019 19:03:02 +0100 Subject: [PATCH] Use transaction for database migration --- qlite/src/database.vala | 10 ++++++++++ qlite/src/table.vala | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/qlite/src/database.vala b/qlite/src/database.vala index d13b9bc4..f58b76b6 100644 --- a/qlite/src/database.vala +++ b/qlite/src/database.vala @@ -38,6 +38,11 @@ public class Database { } private void start_migration() { + try { + exec("BEGIN TRANSACTION"); + } catch (Error e) { + error("SQLite error: %d - %s", db.errcode(), db.errmsg()); + } meta_table.create_table_at_version(expected_version); long old_version = 0; old_version = meta_table.row_with(meta_name, "version")[meta_int_val, -1]; @@ -66,6 +71,11 @@ public class Database { foreach (Table t in tables) { t.post(); } + try { + exec("END TRANSACTION"); + } catch (Error e) { + error("SQLite error: %d - %s", db.errcode(), db.errmsg()); + } } internal int errcode() { diff --git a/qlite/src/table.vala b/qlite/src/table.vala index 6c6ef9de..a5a57c49 100644 --- a/qlite/src/table.vala +++ b/qlite/src/table.vala @@ -48,7 +48,7 @@ public class Table { try { db.exec(@"INSERT INTO _fts_$name(_fts_$name) VALUES('rebuild');"); } catch (Error e) { - error(@"Qlite Error: Rebuilding FTS index: $(e.message)"); + critical(@"Qlite Error: Rebuilding FTS index: $(e.message)"); } } @@ -171,7 +171,7 @@ public class Table { try { db.exec(@"ALTER TABLE $name ADD COLUMN $(c.to_column_definition())"); } catch (Error e) { - error(@"Qlite Error: Add columns for version: $(e.message)"); + critical(@"Qlite Error: Add columns for version: $(e.message)"); } } }