From 5b7bf82edb672d5d5dbd8b1de64532aeec695661 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 2 Mar 2018 19:47:19 -0500 Subject: Handled games with no images For games where no images could be downloaded from Steam, which happens if a game has been removed from the store, the bot will now use a default background. This image is copyright Nintendo. --- database.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'database.cpp') diff --git a/database.cpp b/database.cpp index 953c217..19ba0e0 100644 --- a/database.cpp +++ b/database.cpp @@ -82,6 +82,47 @@ achievement database::getRandomAchievement() const return result; } +bool database::doesGameHaveImages(int gameId) const +{ + std::string queryString = "SELECT COUNT(*) FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1"; + + sqlite3_stmt* ppstmt; + if (sqlite3_prepare_v2( + ppdb_, + queryString.c_str(), + queryString.length(), + &ppstmt, + NULL) != SQLITE_OK) + { + std::string errorMsg = sqlite3_errmsg(ppdb_); + sqlite3_finalize(ppstmt); + + throw std::logic_error(errorMsg); + } + + if (sqlite3_bind_int(ppstmt, 1, gameId) != SQLITE_OK) + { + std::string errorMsg = sqlite3_errmsg(ppdb_); + sqlite3_finalize(ppstmt); + + throw std::logic_error(errorMsg); + } + + if (sqlite3_step(ppstmt) != SQLITE_ROW) + { + std::string errorMsg = sqlite3_errmsg(ppdb_); + sqlite3_finalize(ppstmt); + + throw std::logic_error(errorMsg); + } + + int result = sqlite3_column_int(ppstmt, 0); + + sqlite3_finalize(ppstmt); + + return (result > 0); +} + std::string database::getRandomImageForGame(int gameId) const { std::string queryString = "SELECT filename FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1"; -- cgit 1.4.1