From 11db353ea4cac33caccb005be7d4b72671f20ad9 Mon Sep 17 00:00:00 2001 From: Louie S Date: Sat, 16 Sep 2023 09:36:14 -0400 Subject: removing (hiding) groups working --- db_sqlite.py | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'db_sqlite.py') diff --git a/db_sqlite.py b/db_sqlite.py index 2f20c91..a3620e2 100644 --- a/db_sqlite.py +++ b/db_sqlite.py @@ -79,7 +79,8 @@ def loadFromTables(): record.field("id").value(), record.field("name").value(), record.field("column").value(), - record.field("link").value())) + record.field("link").value(), + record.field("hidden").value())) # Load entries query.exec_("SELECT * FROM entries") @@ -168,3 +169,34 @@ def insertEntry(new_entry): database.close() return output + +def removeGroup(group_id): + """ + Remove a group by id from the database + (actually set hidden to true, don't permanently delete it) + """ + + database = QSqlDatabase.addDatabase("QSQLITE") # SQlite version 3 + database.setDatabaseName(Globals.db_path) + + if not database.open(): + print("Unable to open data source file.") + sys.exit(1) # Error out. TODO consider throwing a dialog instead + + query = QSqlQuery() + + # First, set entries to hidden + query.prepare(""" + UPDATE entries SET hidden = 1 WHERE parent_id = ? + """) + query.addBindValue(group_id) + query.exec_() + + # Now, set the group to hidden + query.prepare(""" + UPDATE groups SET hidden = 1 WHERE id = ? + """) + query.addBindValue(group_id) + query.exec_() + + database.close() -- cgit