summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/db_sqlite.cpp48
-rw-r--r--src/backend/db_sqlite.h3
2 files changed, 49 insertions, 2 deletions
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<Rule *> 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<Rule *> BackendDB::loadRules(int entry_id) {
+ QList<Rule *> 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() {
{
diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h
index 1db61e8..ce2d900 100644
--- a/src/backend/db_sqlite.h
+++ b/src/backend/db_sqlite.h
@@ -16,6 +16,7 @@ class BackendDB : QSqlDatabase {
QList<Entry *> loadEntries();
QList<Entry *> loadEntries(int parent_id);
QList<Rule *> loadRules();
+ 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
@@ -24,7 +25,7 @@ class BackendDB : QSqlDatabase {
void updateRule(int rule); // param datatype TBD
int removeGroup(const Group &group);
int removeEntry(const Entry &entry);
- void removeRule(int rule); // param datatype TBD
+ int removeRule(const Rule &rule);
void cleanHidden();
private: