From 3e1d2e46ceea202120b4ff814fbd872bc6fc60f3 Mon Sep 17 00:00:00 2001 From: Louie S Date: Thu, 14 Mar 2024 18:46:37 -0400 Subject: RulesDialog menu working (functionality WIP) --- src/backend/db_sqlite.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'src/backend/db_sqlite.cpp') diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp index 4319b67..32108e1 100644 --- a/src/backend/db_sqlite.cpp +++ b/src/backend/db_sqlite.cpp @@ -134,7 +134,33 @@ QList BackendDB::loadRules() { QSqlDatabase database(this->openDB()); QSqlQuery query; - query.exec("SELECT * FROM groups"); + query.exec("SELECT * FROM rules"); + while(query.next()) { + output.append(new Rule( + query.record().field("id").value().toInt(), + query.record().field("entry_id").value().toInt(), + (Rule::When) query.record().field("before_after").value().toInt(), + query.record().field("date").value().toDateTime(), + query.record().field("color").value().toString(), + query.record().field("highlight").value().toString())); + } + } + + QSqlDatabase::removeDatabase("qt_sql_default_connection"); + return output; +} + +// load entries +QList BackendDB::loadRules(int entry_id) { + QList output; + + { + QSqlDatabase database(this->openDB()); + QSqlQuery query; + + query.prepare("SELECT * FROM rules WHERE entry_id = ?"); + query.bindValue(0, entry_id); + query.exec(); while(query.next()) { output.append(new Rule( query.record().field("id").value().toInt(), @@ -295,6 +321,26 @@ int BackendDB::removeEntry(const Entry &entry) { return output; } +// return value: number of affected rows +int BackendDB::removeRule(const Rule &rule) { + int output; + + { + QSqlDatabase database(this->openDB()); + QSqlQuery query; + + query.prepare("DELETE FROM rules WHERE id = ?"); + query.bindValue(0, rule.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; +} + // permanently delete removed/hidden groups and entries void BackendDB::cleanHidden() { { -- cgit