modified src/main.cpp +13 -4
| @@ -26,7 +26,7 @@ std::string database_initialization_command = "CREATE TABLE GAME(" |
| 26 | 26 | |
| 27 | 27 | const char* select_all_games_command = "SELECT * FROM GAME;"; |
| 28 | 28 | |
| 29 | | -bool debugRun = false; |
| 29 | +bool debugRun = true; |
| 30 | 30 | |
| 31 | 31 | void printMessage(std::string message) { |
| 32 | 32 | if (debugRun) { |
| @@ -48,7 +48,16 @@ void execute_sql_command(sqlite3* database, std::string command) { |
| 48 | 48 | int calculateFirstGameIdAvailable() { |
| 49 | 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 | 62 | return availableId; |
| 54 | 63 | } |
| @@ -164,8 +173,8 @@ int main(int argc, char const *argv[]) { |
| 164 | 173 | |
| 165 | 174 | games.push_back( |
| 166 | 175 | Game { |
| 167 | | - id, |
| 168 | | - reinterpret_cast<const char*>(gameName), |
| 176 | + id, |
| 177 | + reinterpret_cast<const char*>(gameName), |
| 169 | 178 | reinterpret_cast<const char*>(gamePath) |
| 170 | 179 | } |
| 171 | 180 | ); |
| @@ -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 | ); |