X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=bigscreen%2Ffetch_needs_update.cpp;fp=bigscreen%2Ffetch_needs_update.cpp;h=bbb801e15e2c1cb4ec34aec740f14d9b6047b582;hb=32d2a098bec8a1ace0f86f28110da45d060f8447;hp=0000000000000000000000000000000000000000;hpb=9c78e37258ab59892b8032be8ed2265d2ad2f587;p=ccbs diff --git a/bigscreen/fetch_needs_update.cpp b/bigscreen/fetch_needs_update.cpp new file mode 100644 index 0000000..bbb801e --- /dev/null +++ b/bigscreen/fetch_needs_update.cpp @@ -0,0 +1,26 @@ +#include "fetch_needs_update.h" + +FetchNeedsUpdate::FetchNeedsUpdate(struct timeval last_updated, unsigned tournament, unsigned round, unsigned parallel, bool *result) + : last_updated(last_updated), tournament(tournament), round(round), parallel(parallel), result(result) +{ +} + +void FetchNeedsUpdate::operator() (pqxx::transaction<> &t) +{ + // as we don't seem to have proper handling for timestamps in libpqxx, + // let's ask the database do to the work for us + char buf[256]; + time_t lu = last_updated.tv_sec; + strftime(buf, 256, "%F %T", localtime(&lu)); + + pqxx::result res( t.exec(std::string("SELECT (last_updated > '") + buf + "') AS needs_update FROM bigscreen.active_groups WHERE " + "tournament=" + pqxx::to_string(tournament) + " AND " + "round=" + pqxx::to_string(round) + " AND " + "parallel=" + pqxx::to_string(parallel)) ); + + try { + *result = res.at(0)["needs_update"].as(*result); + } catch (PGSTD::out_of_range &e) { + *result = false; + } +}