diff options
author | Louie S <louie@example.com> | 2024-03-09 18:28:02 -0500 |
---|---|---|
committer | Louie S <louie@example.com> | 2024-03-09 18:28:02 -0500 |
commit | ddee95158867554825092b9c29d8278320b93c61 (patch) | |
tree | 9523c6ef4879017286360ba9efc9ce97056d3ba9 /src/backend | |
parent | 848cdae813648f0a2c39942dc01d8f991787b338 (diff) |
Implemented remove group
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/db_sqlite.cpp | 29 | ||||
-rw-r--r-- | src/backend/db_sqlite.h | 2 |
2 files changed, 28 insertions, 3 deletions
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(); |