diff options
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/db_sqlite.cpp | 21 | ||||
-rw-r--r-- | src/backend/db_sqlite.h | 8 |
2 files changed, 24 insertions, 5 deletions
diff --git a/src/backend/db_sqlite.cpp b/src/backend/db_sqlite.cpp index 9cd73f5..4479b09 100644 --- a/src/backend/db_sqlite.cpp +++ b/src/backend/db_sqlite.cpp @@ -91,7 +91,7 @@ QList<Group *> BackendDB::loadGroups() { } // load entries -QList<Entry *> loadEntries() { +QList<Entry *> BackendDB::loadEntries() { QSqlDatabase database = openDB(); QSqlQuery query; QList<Entry *> output; @@ -116,7 +116,7 @@ QList<Entry *> loadEntries() { } // load entries -QList<Rule *> loadRules() { +QList<Rule *> BackendDB::loadRules() { QSqlDatabase database = openDB(); QSqlQuery query; QList<Rule *> output; @@ -135,3 +135,20 @@ QList<Rule *> loadRules() { database.close(); return output; } + +// insert group to the database (returns 0 if failed) +int BackendDB::insertGroup(const Group &new_group) { + QSqlDatabase database = openDB(); + QSqlQuery query; + int output; + + query.prepare("INSERT INTO groups (name, column, link) VALUES (?, ?, ?)"); + query.bindValue(0, new_group.name); + query.bindValue(1, new_group.column); + query.bindValue(2, new_group.link); + query.exec(); + + output = query.lastInsertId().toInt(); + database.close(); + return output; +} diff --git a/src/backend/db_sqlite.h b/src/backend/db_sqlite.h index 6e94fdd..fb04c00 100644 --- a/src/backend/db_sqlite.h +++ b/src/backend/db_sqlite.h @@ -8,6 +8,8 @@ #include "../group.h" #include "../rule.h" +// TODO rewrite to be a class (see difference between ::addDatabase and ::database) + namespace BackendDB { const QStringList create_table_queries = { "CREATE TABLE groups (" @@ -43,9 +45,9 @@ namespace BackendDB { QList<Group *> loadGroups(); QList<Entry *> loadEntries(); QList<Rule *> loadRules(); - void insertGroup(int new_group); // param datatype TBD - void insertEntry(int new_entry); // param datatype TBD - void insertRule(int new_rule); // param datatype TBD + int insertGroup(const Group &new_group); // param datatype TBD + int insertEntry(int new_entry); // param datatype TBD + int insertRule(int new_rule); // param datatype TBD void updateGroup(int group); // param datatype TBD void updateEntry(int entry); // param datatype TBD void updateRule(int rule); // param datatype TBD |