summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2024-03-15 15:41:31 -0400
committerLouie S <louie@example.com>2024-03-15 15:41:31 -0400
commitd732bd0f74225828455c5863444b0211faf586d0 (patch)
tree4c605e694cc02521c9fddb05a710c62d66a97e55 /src/backend
parent3e1d2e46ceea202120b4ff814fbd872bc6fc60f3 (diff)
Add backend for rules dialog
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/db_sqlite.cpp47
-rw-r--r--src/backend/db_sqlite.h4
2 files changed, 48 insertions, 3 deletions
diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp
index 32108e1..f48089b 100644
--- a/src/backend/db_sqlite.cpp
+++ b/src/backend/db_sqlite.cpp
@@ -197,7 +197,7 @@ int BackendDB::insertGroup(const Group &new_group) {
return output;
}
-// insert group to the database (returns 0 if failed)
+// insert entry to the database (returns 0 if failed)
int BackendDB::insertEntry(const Entry &new_entry) {
int output;
@@ -222,6 +222,29 @@ int BackendDB::insertEntry(const Entry &new_entry) {
return output;
}
+// insert rule to the database (returns 0 if failed)
+int BackendDB::insertRule(const Rule &new_rule) {
+ int output;
+
+ {
+ QSqlDatabase database(this->openDB());
+ QSqlQuery query;
+
+ query.prepare("INSERT INTO rules (entry_id, before_after, date, color, highlight) VALUES (:e_id, :when, :date, :color, :highlight)");
+ query.bindValue(":e_id", new_rule.entry_id);
+ query.bindValue(":when", new_rule.when);
+ query.bindValue(":date", new_rule.date.toString("yyyy-MM-dd"));
+ query.bindValue(":color", new_rule.color);
+ query.bindValue(":highlight", new_rule.highlight);
+ query.exec();
+
+ output = query.lastInsertId().toInt();
+ }
+
+ QSqlDatabase::removeDatabase("qt_sql_default_connection");
+ return output;
+}
+
void BackendDB::updateGroup(const Group &group) {
{
QSqlDatabase database(this->openDB());
@@ -274,6 +297,28 @@ void BackendDB::updateEntry(const Entry &entry) {
QSqlDatabase::removeDatabase("qt_sql_default_connection");
}
+void BackendDB::updateRule(const Rule &rule) {
+ {
+ QSqlDatabase database(this->openDB());
+ QSqlQuery query;
+
+ query.prepare("UPDATE rules SET "
+ "before_after = :when, "
+ "date = :date, "
+ "color = :color, "
+ "highlight = :highlight "
+ "WHERE id = :id");
+ query.bindValue(":when", rule.when);
+ query.bindValue(":date", rule.date.toString("yyyy-MM-dd"));
+ query.bindValue(":color", rule.color);
+ query.bindValue(":highlight", rule.highlight);
+ query.bindValue(":id", rule.id);
+ query.exec();
+ }
+
+ 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) {
diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h
index ce2d900..93ae050 100644
--- a/src/backend/db_sqlite.h
+++ b/src/backend/db_sqlite.h
@@ -19,10 +19,10 @@ class BackendDB : QSqlDatabase {
QList<Rule *> loadRules(int entry_id);
int insertGroup(const Group &new_group);
int insertEntry(const Entry &new_entry);
- int insertRule(int new_rule); // param datatype TBD
+ int insertRule(const Rule &new_rule);
void updateGroup(const Group &group);
void updateEntry(const Entry &entry);
- void updateRule(int rule); // param datatype TBD
+ void updateRule(const Rule &rule);
int removeGroup(const Group &group);
int removeEntry(const Entry &entry);
int removeRule(const Rule &rule);