about summary refs log tree commit diff stats
path: root/database.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'database.cpp')
-rw-r--r--database.cpp41
1 files changed, 41 insertions, 0 deletions
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
82 return result; 82 return result;
83} 83}
84 84
85bool database::doesGameHaveImages(int gameId) const
86{
87 std::string queryString = "SELECT COUNT(*) FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1";
88
89 sqlite3_stmt* ppstmt;
90 if (sqlite3_prepare_v2(
91 ppdb_,
92 queryString.c_str(),
93 queryString.length(),
94 &ppstmt,
95 NULL) != SQLITE_OK)
96 {
97 std::string errorMsg = sqlite3_errmsg(ppdb_);
98 sqlite3_finalize(ppstmt);
99
100 throw std::logic_error(errorMsg);
101 }
102
103 if (sqlite3_bind_int(ppstmt, 1, gameId) != SQLITE_OK)
104 {
105 std::string errorMsg = sqlite3_errmsg(ppdb_);
106 sqlite3_finalize(ppstmt);
107
108 throw std::logic_error(errorMsg);
109 }
110
111 if (sqlite3_step(ppstmt) != SQLITE_ROW)
112 {
113 std::string errorMsg = sqlite3_errmsg(ppdb_);
114 sqlite3_finalize(ppstmt);
115
116 throw std::logic_error(errorMsg);
117 }
118
119 int result = sqlite3_column_int(ppstmt, 0);
120
121 sqlite3_finalize(ppstmt);
122
123 return (result > 0);
124}
125
85std::string database::getRandomImageForGame(int gameId) const 126std::string database::getRandomImageForGame(int gameId) const
86{ 127{
87 std::string queryString = "SELECT filename FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1"; 128 std::string queryString = "SELECT filename FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1";