| @@ -21,12 +21,12 @@ using namespace ftxui; |
| 21 | std::vector<Game> games; | 21 | std::vector<Game> games; |
| 22 | | 22 | |
| 23 | std::string database_initialization_command = | 23 | std::string database_initialization_command = |
| 24 | - "CREATE TABLE GAME(" | 24 | + "CREATE TABLE games(" |
| 25 | - "GAME_ID INT PRIMARY KEY NOT NULL, " | 25 | + "GAME_ID INTEGER PRIMARY KEY AUTOINCREMENT, " |
| 26 | "GAME_NAME TEXT NOT NULL, " | 26 | "GAME_NAME TEXT NOT NULL, " |
| 27 | "GAME_PATH TEXT NOT NULL);"; | 27 | "GAME_PATH TEXT NOT NULL);"; |
| 28 | | 28 | |
| 29 | -std::string select_all_games_command = "SELECT * FROM GAME;"; | 29 | +std::string select_all_games_command = "SELECT * FROM games;"; |
| 30 | | 30 | |
| 31 | bool debugRun = true; | 31 | bool debugRun = true; |
| 32 | | 32 | |
| @@ -47,39 +47,15 @@ void execute_sql_command(sqlite3 *database, std::string command) { |
| 47 | } | 47 | } |
| 48 | } | 48 | } |
| 49 | | 49 | |
| 50 | -auto calculateFirstGameIdAvailable() -> int { | 50 | +void addGame(sqlite3 *database, std::string name, std::string path) { |
| 51 | - int availableId{}; | | |
| 52 | - | | |
| 53 | - std::vector<int> usedIds{}; | | |
| 54 | - for (auto &game : games) { | | |
| 55 | - usedIds.emplace_back(game.getId()); | | |
| 56 | - } | | |
| 57 | - | | |
| 58 | - bool found{true}; | | |
| 59 | - while (found) { | | |
| 60 | - found = std::find(usedIds.begin(), usedIds.end(), availableId) != | | |
| 61 | - std::end(usedIds); | | |
| 62 | - availableId++; | | |
| 63 | - } | | |
| 64 | - | | |
| 65 | - return availableId; | | |
| 66 | -} | | |
| 67 | - | | |
| 68 | -void addGameToDatabase(sqlite3 *database, int id, std::string name, | | |
| 69 | - std::string path) { | | |
| 70 | std::string command = | 51 | std::string command = |
| 71 | - "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES ("; | 52 | + "INSERT INTO games (GAME_NAME, GAME_PATH) VALUES ("; |
| 72 | - command += std::to_string(id) + ", '" + name + "', \"" + path + "\");"; | 53 | + command += "'" + name + "', \"" + path + "\");"; |
| 73 | execute_sql_command(database, command); | 54 | execute_sql_command(database, command); |
| 74 | } | 55 | } |
| 75 | | 56 | |
| 76 | -void addGame(sqlite3 *database, std::string name, std::string path) { | | |
| 77 | - int id = calculateFirstGameIdAvailable(); | | |
| 78 | - addGameToDatabase(database, id, name, path); | | |
| 79 | -} | | |
| 80 | - | | |
| 81 | void removeGame(sqlite3 *database, std::string name) { | 57 | void removeGame(sqlite3 *database, std::string name) { |
| 82 | - std::string command = "DELETE FROM GAME WHERE GAME_NAME="; | 58 | + std::string command = "DELETE FROM games WHERE GAME_NAME="; |
| 83 | command += "'" + name + "';"; | 59 | command += "'" + name + "';"; |
| 84 | execute_sql_command(database, command); | 60 | execute_sql_command(database, command); |
| 85 | } | 61 | } |