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

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