From 9c05cd5b5e9250f3cfd04a98370595db8ef8f697 Mon Sep 17 00:00:00 2001 From: Louie S Date: Wed, 28 Feb 2024 18:39:48 -0500 Subject: Working add_group_form --- src/backend/db_sqlite.cpp | 21 +++++++++++++++++++-- src/backend/db_sqlite.h | 8 +++++--- 2 files changed, 24 insertions(+), 5 deletions(-) (limited to 'src/backend') 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 BackendDB::loadGroups() { } // load entries -QList loadEntries() { +QList BackendDB::loadEntries() { QSqlDatabase database = openDB(); QSqlQuery query; QList output; @@ -116,7 +116,7 @@ QList loadEntries() { } // load entries -QList loadRules() { +QList BackendDB::loadRules() { QSqlDatabase database = openDB(); QSqlQuery query; QList output; @@ -135,3 +135,20 @@ QList 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 loadGroups(); QList loadEntries(); QList 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 -- cgit