From 682f5761b26dd922dd5e9c9ce64ccd6e46d953a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Thu, 19 Oct 2023 19:34:02 +0200 Subject: [PATCH] Propagate updates to all the parent folders --- YACReaderLibrary/db_helper.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/YACReaderLibrary/db_helper.cpp b/YACReaderLibrary/db_helper.cpp index b315a446..c57d3dfe 100644 --- a/YACReaderLibrary/db_helper.cpp +++ b/YACReaderLibrary/db_helper.cpp @@ -1292,13 +1292,22 @@ qulonglong DBHelper::insert(ComicDB *comic, QSqlDatabase &db, bool insertAllInfo query.bindValue(":path", comic->path); query.exec(); + // loop through parents and update their updated field + // TODO: use stored procedures QSqlQuery updateFolder(db); updateFolder.prepare("UPDATE folder SET " "updated = :updated " "WHERE id = :id "); - updateFolder.bindValue(":updated", added); - updateFolder.bindValue(":id", comic->parentId); - updateFolder.exec(); + auto currentParentId = comic->parentId; + while (currentParentId != 1 && currentParentId != 0) { + updateFolder.bindValue(":updated", added); + updateFolder.bindValue(":id", currentParentId); + updateFolder.exec(); + + auto f = loadFolder(currentParentId, db); + currentParentId = f.parentId; + } + //---- return query.lastInsertId().toULongLong(); }