1 #include "fetch_top_scores_for_tournament.h"
3 // small utility function so we can stick TopScores in a std::set
4 bool TopScore::operator< (const TopScore &other) const
6 if (nick != other.nick)
7 return (nick < other.nick);
8 if (title != other.title)
9 return (title < other.title);
10 return (score < other.score);
13 FetchTopScoresForTournament::FetchTopScoresForTournament(unsigned tournament, unsigned num, std::vector<TopScore> *scores)
14 : tournament(tournament), num(num), scores(scores) {}
16 void FetchTopScoresForTournament::operator() (pqxx::transaction<> &t)
18 scores->erase(scores->begin(), scores->end());
20 // Again, this will break if a song has more than one short title
21 pqxx::result res( t.exec(
22 "SELECT nick, title, shorttitle, score FROM scores NATURAL JOIN tournaments JOIN players ON scores.player=players.player NATURAL JOIN songs NATURAL LEFT JOIN songshorttitles WHERE tournament=" +
23 pqxx::to_string(tournament) + " AND score IS NOT NULL ORDER BY score DESC LIMIT " +
24 pqxx::to_string(num)) );
26 for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
29 ts.nick = i["nick"].as(ts.nick);
30 ts.title = i["title"].as(ts.title);
31 ts.shorttitle = i["shorttitle"].as(ts.shorttitle);
32 ts.score = i["score"].as(ts.score);
34 scores->push_back(ts);