juk3n/fluffypublic Fork
⑂ 1664d3e
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.

refactored adding games to database

Adrian Duraj committed 2024-06-20T16:39:47+02:00 Browse files
1664d3e parent: c0929eb
modified src/main.cpp +8 -5
@@ -43,7 +43,12 @@ void execute_sql_command(sqlite3* database, std::string command) {
4343 }
4444 }
4545
46-void addGame(sqlite3* database, int id, std::string name, std::string path) {
46+void addGame(sqlite3* database, std::string name, std::string path) {
47+ int id = games.size() + 1; // calculateId();
48+ addGameToDatabase(database, id, name, path);
49+}
50+
51+void addGameToDatabase(sqlite3* database, int id, std::string name, std::string path) {
4752 std::string command = "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES (";
4853 command += std::to_string(id) + ", '" + name + "', \"" + path + "\");";
4954 execute_sql_command(database, command);
@@ -57,9 +62,7 @@ void removeGame(sqlite3* database, std::string name) {
5762
5863 void initialize_database(sqlite3* database) {
5964 execute_sql_command(database, database_initialization_command);
60- addGame(database, 1, "Devastating Fog", "");
61- addGame(database, 2, "No Pirates Here!", "");
62- printMessage("Database Initialized");
65+ printMessage("Database Initialized");
6366 }
6467
6568 void runGame(sqlite3* database, std::string gameName) {
@@ -110,7 +113,7 @@ void handleCommand(int argc, char const *argv[], sqlite3* database) {
110113 }
111114 }
112115
113- addGame(database, games.size() + 1, gameName, temp);
116+ addGame(database, gameName, temp);
114117 }
115118 break;
116119 }
@@ -43,7 +43,12 @@ void execute_sql_command(sqlite3* database, std::string command) {
43 }43 }
44 }44 }
45 45
46-void addGame(sqlite3* database, int id, std::string name, std::string path) {46+void addGame(sqlite3* database, std::string name, std::string path) {
47+ int id = games.size() + 1; // calculateId();
48+ addGameToDatabase(database, id, name, path);
49+}
50+
51+void addGameToDatabase(sqlite3* database, int id, std::string name, std::string path) {
47 std::string command = "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES (";52 std::string command = "INSERT INTO GAME (GAME_ID, GAME_NAME, GAME_PATH) VALUES (";
48 command += std::to_string(id) + ", '" + name + "', \"" + path + "\");";53 command += std::to_string(id) + ", '" + name + "', \"" + path + "\");";
49 execute_sql_command(database, command);54 execute_sql_command(database, command);
@@ -57,9 +62,7 @@ void removeGame(sqlite3* database, std::string name) {
57 62
58 void initialize_database(sqlite3* database) {63 void initialize_database(sqlite3* database) {
59 execute_sql_command(database, database_initialization_command);64 execute_sql_command(database, database_initialization_command);
60- addGame(database, 1, "Devastating Fog", "");65+ printMessage("Database Initialized");
61- addGame(database, 2, "No Pirates Here!", "");
62- printMessage("Database Initialized");
63 }66 }
64 67
65 void runGame(sqlite3* database, std::string gameName) {68 void runGame(sqlite3* database, std::string gameName) {
@@ -110,7 +113,7 @@ void handleCommand(int argc, char const *argv[], sqlite3* database) {
110 }113 }
111 }114 }
112 115
113- addGame(database, games.size() + 1, gameName, temp);116+ addGame(database, gameName, temp);
114 }117 }
115 break;118 break;
116 }119 }