]> git.sesse.net Git - ccbs/blob - bigscreen/fetch_highscore.cpp
Port to pqxx3, where we need the widestring traits available at parse time.
[ccbs] / bigscreen / fetch_highscore.cpp
1 #include "fetch_highscore.h"
2
3 FetchHighscore::FetchHighscore(unsigned song, Highscore *hs)
4         : song(song), hs(hs) {}
5         
6 void FetchHighscore::operator() (pqxx::transaction<> &t)
7 {
8         pqxx::result res( t.exec("SELECT score,nick,tournamentname FROM scores NATURAL JOIN players NATURAL JOIN tournaments WHERE song=" + pqxx::to_string(song) + " AND score IS NOT NULL ORDER BY score DESC LIMIT 1") );
9
10         hs->song = song;
11         
12         try {
13                 pqxx::result::tuple highscore = res.at(0);
14                 
15                 hs->score = highscore["score"].as(hs->score);
16                 hs->nick = highscore["nick"].as(hs->nick);
17                 hs->tournament_name = highscore["tournamentname"].as(hs->tournament_name);
18         } catch (PGSTD::out_of_range &e) {
19                 hs->score = -1;
20         }
21 }