]> git.sesse.net Git - ccbs/blobdiff - bigscreen/fetch_current_tournament.cpp
Move Tournament and FetchCurrentTournament into its own file.
[ccbs] / bigscreen / fetch_current_tournament.cpp
diff --git a/bigscreen/fetch_current_tournament.cpp b/bigscreen/fetch_current_tournament.cpp
new file mode 100644 (file)
index 0000000..364d8b3
--- /dev/null
@@ -0,0 +1,16 @@
+#include "fetch_current_tournament.h"
+
+FetchCurrentTournament::FetchCurrentTournament(Tournament *tourn) : tourn(tourn) {}
+void FetchCurrentTournament::operator() (pqxx::transaction<> &t)
+{
+       pqxx::result res( t.exec("SELECT * FROM bigscreen.active_tournament NATURAL JOIN tournaments") );
+       try {
+               pqxx::result::tuple tournament = res.at(0);
+
+               tourn->id = tournament["tournament"].as(tourn->id);
+               tourn->name = tournament["tournamentname"].as(tourn->name);
+       } catch (PGSTD::out_of_range &e) {
+               tourn->id = -1;
+               tourn->name = "";
+       }
+}