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.

25 lines
1.0 KiB

  1. #include <ctime>
  2. #include <db/db.h>
  3. #include <db/statements/builder/SelectStatementBuilder.h>
  4. #include <util/calendar_parsing.h>
  5. #include <util/notifications.h>
  6. namespace db {
  7. void fetch_alarms(sql::Database *db, uint32_t interval) {
  8. std::time_t now = std::time(nullptr);
  9. stmt::Statement select_alarms = stmt::Statement::select().columns("absolute_trigger, summary, description").from_table("alarms").inner_join("events", "events.id = alarms.event_id").where("absolute_trigger > " + std::to_string(now) + " AND absolute_trigger < " + std::to_string(now + interval)).close();
  10. try {
  11. sql::Statement query(*db, select_alarms.str());
  12. while (query.executeStep()) {
  13. uint32_t absolute_trigger = query.getColumn(0);
  14. std::string summary = query.getColumn(1);
  15. std::string description = query.getColumn(2);
  16. util::notify(description, summary + std::to_string(absolute_trigger - now));
  17. }
  18. } catch (std::exception& e) {
  19. std::cout << "Exception: " << e.what() << std::endl;
  20. }
  21. }
  22. }