juk3n/fluffypublic Fork
⑂ d0e0dee
Commits
⬇ Clone ▾
git clone https://git.rickub.com/juk3n/fluffy.git
git clone ssh://git@rickub.com/juk3n/fluffy.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

added calculating available id

Adrian Duraj committed 2024-06-20T18:16:09+02:00 Browse files
d0e0dee parent: 643c6dd
modified src/main.cpp +13 -4
@@ -26,7 +26,7 @@ std::string database_initialization_command = "CREATE TABLE GAME("
2626
2727 const char* select_all_games_command = "SELECT * FROM GAME;";
2828
29-bool debugRun = false;
29+bool debugRun = true;
3030
3131 void printMessage(std::string message) {
3232 if (debugRun) {
@@ -48,7 +48,16 @@ void execute_sql_command(sqlite3* database, std::string command) {
4848 int calculateFirstGameIdAvailable() {
4949 int availableId{};
5050
51- availableId = games.size() + 1;
51+ std::vector<int> usedIds{};
52+ for (auto& game : games) {
53+ usedIds.push_back(game.getId());
54+ }
55+
56+ bool found{ true };
57+ while(found) {
58+ found = std::find(usedIds.begin(), usedIds.end(), availableId) != std::end(usedIds);
59+ availableId++;
60+ }
5261
5362 return availableId;
5463 }
@@ -164,8 +173,8 @@ int main(int argc, char const *argv[]) {
164173
165174 games.push_back(
166175 Game {
167- id,
168- reinterpret_cast<const char*>(gameName),
176+ id,
177+ reinterpret_cast<const char*>(gameName),
169178 reinterpret_cast<const char*>(gamePath)
170179 }
171180 );
@@ -26,7 +26,7 @@ std::string database_initialization_command = "CREATE TABLE GAME("
26 26
27 const char* select_all_games_command = "SELECT * FROM GAME;";27 const char* select_all_games_command = "SELECT * FROM GAME;";
28 28
29-bool debugRun = false;29+bool debugRun = true;
30 30
31 void printMessage(std::string message) {31 void printMessage(std::string message) {
32 if (debugRun) {32 if (debugRun) {
@@ -48,7 +48,16 @@ void execute_sql_command(sqlite3* database, std::string command) {
48 int calculateFirstGameIdAvailable() {48 int calculateFirstGameIdAvailable() {
49 int availableId{};49 int availableId{};
50 50
51- availableId = games.size() + 1;51+ std::vector<int> usedIds{};
52+ for (auto& game : games) {
53+ usedIds.push_back(game.getId());
54+ }
55+
56+ bool found{ true };
57+ while(found) {
58+ found = std::find(usedIds.begin(), usedIds.end(), availableId) != std::end(usedIds);
59+ availableId++;
60+ }
52 61
53 return availableId;62 return availableId;
54 }63 }
@@ -164,8 +173,8 @@ int main(int argc, char const *argv[]) {
164 173
165 games.push_back(174 games.push_back(
166 Game {175 Game {
167- id, 176+ id,
168- reinterpret_cast<const char*>(gameName), 177+ reinterpret_cast<const char*>(gameName),
169 reinterpret_cast<const char*>(gamePath)178 reinterpret_cast<const char*>(gamePath)
170 }179 }
171 );180 );