X-Git-Url: https://git.sesse.net/?p=ccbs;a=blobdiff_plain;f=bigscreen%2Ffetch_group.cpp;h=bdaa0c9a9b309e469e24fde3db634eb51d983030;hp=7e131c437951a4022e7a04017e2373cc6cc2db5b;hb=07f65e88e6fd4ebbe8c055f3acd0385f9b64f238;hpb=8970b43d021e65f07ed4d279185c5062b4f9ee4a diff --git a/bigscreen/fetch_group.cpp b/bigscreen/fetch_group.cpp index 7e131c4..bdaa0c9 100644 --- a/bigscreen/fetch_group.cpp +++ b/bigscreen/fetch_group.cpp @@ -5,7 +5,8 @@ FetchGroup::FetchGroup(unsigned tournament, unsigned round, unsigned parallel, G 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 " + + // note: this _will_ break if any song has more than one short title! + pqxx::result res( t.exec("SELECT round,parallel,position,playmode,difficulty,songnumber,player,nick,song,title,COALESCE(shorttitle,title) AS shorttitle,artist,chosen,score FROM roundparticipation NATURAL JOIN players NATURAL JOIN scores NATURAL LEFT JOIN songs NATURAL LEFT JOIN songshorttitles WHERE " "tournament=" + pqxx::to_string(tournament) + " AND " + "round=" + pqxx::to_string(round) + " AND " + "parallel=" + pqxx::to_string(parallel) + " " + @@ -18,16 +19,16 @@ void FetchGroup::operator() (pqxx::transaction<> &t) // 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) { + if (i["player"].as(curr_player) != curr_player) { Player p; - p.id = i["player"]; + p.id = i["player"].as(p.id); p.nick = i["nick"].as(p.nick); p.total = 0; p.rank = 1; curr_group.players.push_back(p); - curr_player = i["player"]; + curr_player = i["player"].as(curr_player); } // note: we _will_ get some duplication here (multiple identical Song @@ -35,15 +36,25 @@ void FetchGroup::operator() (pqxx::transaction<> &t) 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); + if (i["song"].is_null()) { + so.id = -1; + } else { + so.id = i["song"].as(so.id); + so.title = i["title"].as(so.title); + so.artist = i["artist"].as(so.artist); + so.short_title = i["shorttitle"].as(so.short_title); + } 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); + sc.chosen = i["chosen"].as(sc.chosen); + + if (i["score"].is_null()) { + sc.score = -1; + } else { + sc.score = i["score"].as(sc.score); + } + + curr_group.players[curr_group.players.size() - 1].scores.push_back(sc); } }