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.

30 lines
1018 B

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