From 098ef40d13447414edba70701523deac6dd261b3 Mon Sep 17 00:00:00 2001 From: Benoit Lavenier <benoit.lavenier@e-is.pro> Date: Wed, 14 Jun 2023 14:32:23 +0200 Subject: [PATCH] fix(1448): Should not start a SQL transaction that will not be committed - close #1448 --- app/lib/dal/sqliteDAL/MetaDAL.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/lib/dal/sqliteDAL/MetaDAL.ts b/app/lib/dal/sqliteDAL/MetaDAL.ts index 82dfe8b49..35efb4d03 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 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