]> git.sesse.net Git - ccbs/blobdiff - bigscreen/fetch_max_score_for_song.cpp
Add (a rather sizable chunk of) code for determining the possible best and worst...
[ccbs] / bigscreen / fetch_max_score_for_song.cpp
diff --git a/bigscreen/fetch_max_score_for_song.cpp b/bigscreen/fetch_max_score_for_song.cpp
new file mode 100644 (file)
index 0000000..efac925
--- /dev/null
@@ -0,0 +1,13 @@
+#include "fetch_max_score_for_song.h"
+
+FetchMaxScoreForSong::FetchMaxScoreForSong(unsigned tournament, unsigned song, unsigned *score)
+       : tournament(tournament), song(song), score(score) {}
+       
+void FetchMaxScoreForSong::operator() (pqxx::transaction<> &t)
+{
+       pqxx::result res( t.exec("SELECT MAX(feetrating)*1000 AS max_score FROM songratings WHERE song=" +
+               pqxx::to_string(song) + " AND machine=( SELECT machine FROM tournaments WHERE tournament=" +
+               pqxx::to_string(tournament) + ")") );
+       
+       *score = res.at(0)["max_score"].as(*score);
+}