From bbe334b6c9249fea57dee53a0804693dab46f03c Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 2 Mar 2018 18:01:31 -0500 Subject: Added overlay shadow, achievement title wrapping, and date The canonical title font is Roboto Bold and the date font is Roboto Medium. --- database.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'database.cpp') diff --git a/database.cpp b/database.cpp index 2885d1f..953c217 100644 --- a/database.cpp +++ b/database.cpp @@ -1,6 +1,8 @@ #include "database.h" #include #include +#include +#include database::database(std::string path) { @@ -120,3 +122,55 @@ std::string database::getRandomImageForGame(int gameId) const return result; } + +did database::getRandomDidForAchievement(int achievementId) const +{ + std::string queryString = "SELECT profile_id, DATETIME(achieved_at) FROM dids WHERE achievement_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, achievementId) != 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); + } + + did result; + result.profileId = sqlite3_column_int(ppstmt, 0); + + std::tm achievedAt = {}; + + std::stringstream dateParser; + dateParser << reinterpret_cast(sqlite3_column_text(ppstmt, 1)); + dateParser >> std::get_time(&achievedAt, "%Y-%m-%d %H:%M:%S"); + + std::stringstream dateFormatter; + dateFormatter << std::put_time(&achievedAt, "%m/%d/%Y"); + result.date = dateFormatter.str(); + + sqlite3_finalize(ppstmt); + + return result; +} -- cgit 1.4.1