From ddee95158867554825092b9c29d8278320b93c61 Mon Sep 17 00:00:00 2001 From: Louie S Date: Sat, 9 Mar 2024 18:28:02 -0500 Subject: Implemented remove group --- src/backend/db_sqlite.cpp | 29 +++++++++++++++++++++++++++-- src/backend/db_sqlite.h | 2 +- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src/backend') diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp index 6490bb1..91bb3e5 100644 --- a/src/backend/db_sqlite.cpp +++ b/src/backend/db_sqlite.cpp @@ -201,8 +201,6 @@ void BackendDB::updateGroup(const Group &group) { QSqlDatabase database(this->openDB()); QSqlQuery query; - qDebug() << group.name; - query.prepare("UPDATE groups SET " "name = :name, " "column = :column, " @@ -220,6 +218,33 @@ void BackendDB::updateGroup(const Group &group) { QSqlDatabase::removeDatabase("qt_sql_default_connection"); } +// hide group and entries belonging to group +// return value: number of affected rows +int BackendDB::removeGroup(const Group &group) { + int output; + + { + QSqlDatabase database(this->openDB()); + QSqlQuery query; + + // First, set entries to hidden + query.prepare("UPDATE entries SET hidden = 1 WHERE parent_id = ?"); + query.bindValue(0, group.id); + query.exec(); + + // Now, set the group to hidden + query.prepare("UPDATE groups SET hidden = 1 WHERE id = ?"); + query.bindValue(0, group.id); + query.exec(); + + // FIXME not sure if this also needs to be called after the first query... + output = query.numRowsAffected(); + } + + QSqlDatabase::removeDatabase("qt_sql_default_connection"); + return output; +} + QString BackendDB::getDBPath() { QSettings settings; settings.beginGroup("paths"); diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h index b138dc6..c2e8ac7 100644 --- a/src/backend/db_sqlite.h +++ b/src/backend/db_sqlite.h @@ -22,7 +22,7 @@ class BackendDB : QSqlDatabase { void updateGroup(const Group &group); void updateEntry(int entry); // param datatype TBD void updateRule(int rule); // param datatype TBD - void removeGroup(int group); // param datatype TBD + int removeGroup(const Group &group); void removeEntry(int entry); // param datatype TBD void removeRule(int rule); // param datatype TBD void cleanHidden(); -- cgit