]> git.sesse.net Git - ccbs/blob - bigscreen/fetch_needs_update.cpp
Adjusted the fade times a bit.
[ccbs] / bigscreen / fetch_needs_update.cpp
1 #include "fetch_needs_update.h"
2
3 FetchNeedsUpdate::FetchNeedsUpdate(struct timeval last_updated, unsigned tournament, unsigned round, unsigned parallel, bool *result)
4         : last_updated(last_updated), tournament(tournament), round(round), parallel(parallel), result(result)
5 {
6 }
7
8 void FetchNeedsUpdate::operator() (pqxx::transaction<> &t)
9 {
10         // as we don't seem to have proper handling for timestamps in libpqxx,
11         // let's ask the database do to the work for us
12         char buf[256];
13         time_t lu = last_updated.tv_sec;
14         strftime(buf, 256, "%F %T", localtime(&lu));
15         
16         pqxx::result res( t.exec(std::string("SELECT (last_updated > '") + buf + "') AS needs_update FROM bigscreen.active_groups WHERE "
17                 "tournament=" + pqxx::to_string(tournament) + " AND "
18                 "round=" + pqxx::to_string(round) + " AND "
19                 "parallel=" + pqxx::to_string(parallel)) );
20
21         try {
22                 *result = res.at(0)["needs_update"].as(*result);
23         } catch (PGSTD::out_of_range &e) {
24                 *result = false;
25         }
26 }