Browse Source

fetch alarms now alerts with dummy notifcation

main
Stefan Pranger 3 years ago
parent
commit
776c06122a
  1. 19
      db/fetch_alarms.h

19
db/fetch_alarms.h

@ -2,28 +2,23 @@
#include <db/db.h> #include <db/db.h>
#include <db/statements/builder/SelectStatementBuilder.h> #include <db/statements/builder/SelectStatementBuilder.h>
#include <util/calendar_parsing.h>
#include <util/notifications.h>
namespace db { namespace db {
void fetch_alarms(sql::Database *db, uint32_t interval) { void fetch_alarms(sql::Database *db, uint32_t interval) {
std::time_t now = std::time(nullptr); std::time_t now = std::time(nullptr);
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();
DEBUG << select_alarms.str();
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();
try { try {
sql::Statement query(*db, select_alarms.str()); sql::Statement query(*db, select_alarms.str());
query.bind(1, now + interval);
query.bind(2, now);
DEBUG << query.getExpandedSQL();
while (query.executeStep())
{
uint32_t dtstart = query.getColumn(0);
while (query.executeStep()) {
uint32_t absolute_trigger = query.getColumn(0);
std::string summary = query.getColumn(1); std::string summary = query.getColumn(1);
std::string description = query.getColumn(2); std::string description = query.getColumn(2);
DEBUG << dtstart << ", " << summary << ", " << description;
util::notify(description, summary + std::to_string(absolute_trigger - now));
} }
}
catch (std::exception& e)
{
} catch (std::exception& e) {
std::cout << "Exception: " << e.what() << std::endl; std::cout << "Exception: " << e.what() << std::endl;
} }
} }

Loading…
Cancel
Save