From 20b9ea1a0a1d6f43af9fadeea1ad30aa2304b778 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sat, 19 Feb 2005 16:42:37 +0000 Subject: [PATCH] Handle NULL values in scores better. --- bigscreen/fetch_group.cpp | 19 +++++++++++++++---- bigscreen/group.h | 4 ++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bigscreen/fetch_group.cpp b/bigscreen/fetch_group.cpp index e1d0112..7962897 100644 --- a/bigscreen/fetch_group.cpp +++ b/bigscreen/fetch_group.cpp @@ -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); } diff --git a/bigscreen/group.h b/bigscreen/group.h index f6348c0..c57f7b3 100644 --- a/bigscreen/group.h +++ b/bigscreen/group.h @@ -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; -- 2.39.2