--- /dev/null
+#include "fetch_group.h"
+
+FetchGroup::FetchGroup(unsigned tournament, unsigned round, unsigned parallel, Group *group) :
+ tournament(tournament), round(round), parallel(parallel), dest_group(group) {}
+
+void FetchGroup::operator() (pqxx::transaction<> &t)
+{
+ 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 " +
+ "tournament=" + pqxx::to_string(tournament) + " AND " +
+ "round=" + pqxx::to_string(round) + " AND " +
+ "parallel=" + pqxx::to_string(parallel) + " " +
+ "ORDER BY position,songnumber") );
+
+ curr_group.tournament = tournament;
+ curr_group.round = round;
+ curr_group.parallel = parallel;
+
+ // massage the data we get back into a Group object and children
+ int curr_player = -1;
+ for (pqxx::result::const_iterator i = res.begin(); i != res.end(); ++i) {
+ if (i["player"] != curr_player) {
+ Player p;
+
+ p.id = i["player"];
+ p.nick = i["nick"].as(p.nick);
+ p.total = 0;
+ p.rank = 1;
+ curr_group.players.push_back(p);
+
+ curr_player = i["player"];
+ }
+
+ // note: we _will_ get some duplication here (multiple identical Song
+ // objects), but it isn't the end of the world
+ Score sc;
+ Song so;
+
+ so.id = i["song"].as(so.id);
+ so.title = i["song"].as(so.title);
+ so.artist = i["song"].as(so.artist);
+
+ sc.song = so;
+ sc.chosen = i["chosen"].as(s.chosen);
+ sc.score = i["score"].as(s.score);
+
+ curr_group.players[curr.group.players.size() - 1].scores.push_back(sc);
+ }
+}
+
+void FetchGroup::OnCommit()
+{
+ *dest_group = curr_group;
+}