diff options
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r-- | frontend/GameData.cpp | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp index b036695..c8f47e3 100644 --- a/frontend/GameData.cpp +++ b/frontend/GameData.cpp @@ -34,24 +34,47 @@ static const unordered_map<string, ObjectType> type_map = { }; Object * GameData::create_object(const string & name) { - DBStatement query = this->db->prepare("select type, omschrijving from Objecten where naam = ?"); - query.bind(name); + static DBStatement query = this->db->prepare(R"( + select + type, + omschrijving, + minimumwaarde, + maximumwaarde, + bescherming + from Objecten + where lower(naam) = lower(?) + limit 1 + )"); + query.reset() + .bind(name) + ; try { auto row = query.row(); string type = row.col<const char *>(0); - const char * description = row.col<const char *>(1); if (!type_map.contains(type)) throw std::exception(); - return ObjectFactory::create_object(type_map.at(type), name.c_str(), description); + return ObjectFactory::create_object({ + .name = name.c_str(), + .description = row.col<const char *>(1), + .type = type_map.at(type), + .min_value = row.col<int>(2), + .max_value = row.col<int>(3), + .protection = row.col<int>(4), + }); } catch (...) { return ObjectFactory::create_object(name.c_str()); } } void GameData::leaderbord_add(const string & name, unsigned int gold) { - this->db->prepare("insert into Leaderboard (naam, goudstukken) values (?, ?)") + static DBStatement stmt = this->db->prepare(R"( + insert into Leaderboard (naam, goudstukken) + values (?, ?) + )"); + stmt.reset() .bind(name) .bind(gold) - .execute(); + ; + stmt.execute(); } |