Handle NULL values in scores better.
authorSteinar H. Gunderson <sesse@samfundet.no>
Sat, 19 Feb 2005 16:42:37 +0000 (16:42 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Sat, 19 Feb 2005 16:42:37 +0000 (16:42 +0000)
bigscreen/fetch_group.cpp
bigscreen/group.h

index e1d0112..7962897 100644 (file)
@@ -35,13 +35,24 @@ 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["song"].as(so.title);
+                       so.artist = i["song"].as(so.artist);
+               }
        
                sc.song = so;
                sc.chosen = i["chosen"].as(sc.chosen);
-               sc.score = i["score"].as(sc.score);
+
+               if (i["score"].is_null()) {
+                       sc.score = -1;
+               } else {
+                       sc.score = i["score"].as(sc.score);
+               }
+
+               std::printf("score: %u\n", sc.score);
                
                curr_group.players[curr_group.players.size() - 1].scores.push_back(sc);
        }
index f6348c0..c57f7b3 100644 (file)
@@ -6,13 +6,13 @@
 
 /* This more or less mimics the structures from show-tournament.pl */
 struct Song {
-       unsigned id;
+       int id;
        widestring title, artist;
 };
 struct Score {
        Song song;
        bool chosen;
-       unsigned score;
+       int score;
 };
 struct Player {
        unsigned id;