1 #include "fetch_group.h"
3 FetchGroup::FetchGroup(unsigned tournament, unsigned round, unsigned parallel, Group *group) :
4 tournament(tournament), round(round), parallel(parallel), dest_group(group) {}
6 void FetchGroup::operator() (pqxx::transaction<> &t)
8 pqxx::result res( t.exec("SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick,song,title,artist,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs WHERE "
9 "tournament=" + pqxx::to_string(tournament) + " AND " +
10 "round=" + pqxx::to_string(round) + " AND " +
11 "parallel=" + pqxx::to_string(parallel) + " " +
12 "ORDER BY position,songnumber") );
14 curr_group.tournament = tournament;
15 curr_group.round = round;
16 curr_group.parallel = parallel;
18 // massage the data we get back into a Group object and children
20 for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
21 if (i["player"].as(curr_player) != curr_player) {
24 p.id = i["player"].as(p.id);
25 p.nick = i["nick"].as(p.nick);
28 curr_group.players.push_back(p);
30 curr_player = i["player"].as(curr_player);
33 // note: we _will_ get some duplication here (multiple identical Song
34 // objects), but it isn't the end of the world
38 so.id = i["song"].as(so.id);
39 so.title = i["song"].as(so.title);
40 so.artist = i["song"].as(so.artist);
43 sc.chosen = i["chosen"].as(sc.chosen);
44 sc.score = i["score"].as(sc.score);
46 curr_group.players[curr_group.players.size() - 1].scores.push_back(sc);
50 void FetchGroup::OnCommit()
52 *dest_group = curr_group;