From 0e55e4d2d7bdd3e1372b9d90e2689edf965af591 Mon Sep 17 00:00:00 2001 From: Stefan Pranger Date: Fri, 2 Jul 2021 21:30:50 +0200 Subject: [PATCH] split up update.h --- db/update.cpp | 31 +++++++++++++++++++++++++++++++ db/update.h | 11 ++--------- 2 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 db/update.cpp diff --git a/db/update.cpp b/db/update.cpp new file mode 100644 index 0000000..d8524ce --- /dev/null +++ b/db/update.cpp @@ -0,0 +1,31 @@ +#include +#include + +namespace db { + uint32_t insert_events(sql::Database *db, const ical::IcalObject *object) { + DEBUG << *object; + uint32_t event_id; + for(auto const& event : object->get_events()) { + stmt::Statement insert_object = stmt::Statement::insert().table("events").columns("uid, summary, dtstart, dtend").values().row(event->get_db_row()).close(); + DEBUG << insert_object.str(); + db->exec(insert_object.str()); + event_id = db->execAndGet("SELECT last_insert_rowid();"); + DEBUG << event_id; + for(auto const& alarm : event->get_alarms()) { + insert_alarm(db, &alarm, event_id); + } + } + return 0; + } + + uint32_t insert_alarm(sql::Database *db, const ical::Alarm *alarm, const uint32_t event_id) { + std::vector row = alarm->get_db_row(); + row.push_back(std::to_string(event_id)); + stmt::Statement insert_alarm = stmt::Statement::insert().table("alarms").columns("action, description, absolute_trigger, eventID").values().row(row).close(); + + DEBUG << insert_alarm.str(); + db->exec(insert_alarm.str()); + + return 0; + } +} diff --git a/db/update.h b/db/update.h index 0f10d57..9d4d200 100644 --- a/db/update.h +++ b/db/update.h @@ -4,13 +4,6 @@ #include namespace db { - uint32_t insert_object(sql::Database *db, const ical::IcalObject *object) { - DEBUG << *object; - for(auto const& event : object->get_events()) { - stmt::Statement insert_object = stmt::Statement::insert().table("events").columns("uid, summary, dtstart, dtend").values().row(event->get_db_row()).close(); - DEBUG << insert_object.str(); - db->exec(insert_object.str()); - } - return 0; - } + uint32_t insert_events(sql::Database *db, const ical::IcalObject *object); + uint32_t insert_alarm(sql::Database *db, const ical::Alarm *alarm, const uint32_t event_id); }