From 5a96bc7a6798a7e8e9c7684670a020d849633c3a Mon Sep 17 00:00:00 2001
From: Benoit Lavenier <benoit.lavenier@e-is.pro>
Date: Thu, 15 Jun 2023 15:30:48 +0200
Subject: [PATCH] fix(1448): Should not start a SQL transaction that will not
 be committed - close #1448

---
 app/lib/dal/sqliteDAL/MetaDAL.ts | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/app/lib/dal/sqliteDAL/MetaDAL.ts b/app/lib/dal/sqliteDAL/MetaDAL.ts
index 82dfe8b49..7784a17cf 100644
--- a/app/lib/dal/sqliteDAL/MetaDAL.ts
+++ b/app/lib/dal/sqliteDAL/MetaDAL.ts
@@ -219,11 +219,12 @@ export class MetaDAL extends AbstractSQLite<DBMeta> {
       // Add new columns 'issuer' and 'recipient'
       try {
         await txsDAL.exec(
-          "BEGIN;" +
-            "ALTER TABLE txs ADD COLUMN issuer VARCHAR(50) NULL;" +
+          "ALTER TABLE txs ADD COLUMN issuer VARCHAR(50) NULL;" +
             "ALTER TABLE txs ADD COLUMN recipient VARCHAR(50) NULL;" +
-            "UOPDATE txs SET issuer = SUBSTR(issuers, 2, LENGTH(issuers) - 4) WHERE issuer IS NULL AND issuers NOT LIKE '%,%';" +
-            "UOPDATE txs SET recipient = SUBSTR(recipients, 2, LENGTH(recipients) - 4) WHERE recipient IS NULL AND recipients NOT LIKE '%,%';" +
+            // SHOULD start transaction after ALTER TABLE, to avoid leaving a not closed transaction, if failed - close #1448
+            "BEGIN;" +
+            "UPDATE txs SET issuer = SUBSTR(issuers, 2, LENGTH(issuers) - 4) WHERE issuer IS NULL AND issuers NOT LIKE '%,%';" +
+            "UPDATE txs SET recipient = SUBSTR(recipients, 2, LENGTH(recipients) - 4) WHERE recipient IS NULL AND recipients NOT LIKE '%,%';" +
             "COMMIT;"
         );
       } catch (err) {
-- 
GitLab