]> git.sesse.net Git - ccbs/blobdiff - bigscreen/fetch_group.cpp
Add a line for "needed to secure qualifiction"/"needed to qualify". SQL cleanups...
[ccbs] / bigscreen / fetch_group.cpp
index ff719506d0479e61a17751014c3569950753dfd8..7bca2f63e42b06018227716c6198df3a66929290 100644 (file)
@@ -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 numqualifying,playmode,difficulty,position,songnumber,player,nick,song,title,COALESCE(shorttitle,title) AS shorttitle,artist,chosen,score FROM rounds NATURAL JOIN 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,10 +19,13 @@ 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) {
+               curr_group.num_qualifying = i["numqualifying"].as(curr_group.num_qualifying);
+               
                if (i["player"].as(curr_player) != curr_player) {
                        Player p;
 
                        p.id = i["player"].as(p.id);
+                       p.position = i["position"].as(p.id);
                        p.nick = i["nick"].as(p.nick);
                        p.total = 0;
                        p.rank = 1;
@@ -39,8 +43,9 @@ void FetchGroup::operator() (pqxx::transaction<> &t)
                        so.id = -1;
                } else {
                        so.id = i["song"].as(so.id);
-                       so.title = i["song"].as(so.title);
-                       so.artist = i["song"].as(so.artist);
+                       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;
@@ -50,6 +55,7 @@ void FetchGroup::operator() (pqxx::transaction<> &t)
                        sc.score = -1;
                } else {
                        sc.score = i["score"].as(sc.score);
+                       curr_group.players[curr_group.players.size() - 1].total += sc.score;
                }
 
                curr_group.players[curr_group.players.size() - 1].scores.push_back(sc);