You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

  1. #include <db/update.h>
  2. #include <db/statements/builder/InsertStatementBuilder.h>
  3. namespace db {
  4. uint32_t insert_events(sql::Database *db, const ical::IcalObject *object) {
  5. DEBUG << *object;
  6. uint32_t event_id;
  7. for(auto const& event : object->get_events()) {
  8. stmt::Statement insert_object = stmt::Statement::insert().table("events").columns("uid, summary, dtstart, dtend").values().row(event->get_db_row()).close();
  9. DEBUG << insert_object.str();
  10. db->exec(insert_object.str());
  11. event_id = db->execAndGet("SELECT last_insert_rowid();");
  12. DEBUG << event_id;
  13. for(auto const& alarm : event->get_alarms()) {
  14. insert_alarm(db, &alarm, event_id);
  15. }
  16. }
  17. return 0;
  18. }
  19. uint32_t insert_alarm(sql::Database *db, const ical::Alarm *alarm, const uint32_t event_id) {
  20. std::vector<std::string> row = alarm->get_db_row();
  21. row.push_back(std::to_string(event_id));
  22. stmt::Statement insert_alarm = stmt::Statement::insert().table("alarms").columns("action, description, absolute_trigger, eventID").values().row(row).close();
  23. DEBUG << insert_alarm.str();
  24. db->exec(insert_alarm.str());
  25. return 0;
  26. }
  27. }