modified src/main.cpp +6 -2
| @@ -169,12 +169,16 @@ auto runConsoleApp(sqlite3* database) -> void { |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | auto main(int argc, char const *argv[]) -> int { |
| 172 | | - bool newCreation = not std::filesystem::exists("data.db"); |
| 172 | + auto appDirectory{ std::filesystem::path(argv[0])}; |
| 173 | + std::cout << appDirectory.parent_path().string() << std::endl; |
| 174 | + auto databasePath{ std::filesystem::path(appDirectory.parent_path().string() + "/data.db")}; |
| 175 | + std::cout << databasePath.string() << std::endl; |
| 176 | + bool newCreation = not std::filesystem::exists(databasePath.string()); |
| 173 | 177 | char *messageError; |
| 174 | 178 | sqlite3 *database; |
| 175 | 179 | sqlite3_stmt *stmt; |
| 176 | 180 | int exit = 0; |
| 177 | | - exit = sqlite3_open("data.db", &database); |
| 181 | + exit = sqlite3_open(databasePath.c_str(), &database); |
| 178 | 182 | |
| 179 | 183 | if (exit) { |
| 180 | 184 | std::cerr << "Error opening database" << sqlite3_errmsg(database) |
| @@ -169,12 +169,16 @@ auto runConsoleApp(sqlite3* database) -> void { |
| 169 | } | 169 | } |
| 170 | | 170 | |
| 171 | auto main(int argc, char const *argv[]) -> int { | 171 | auto main(int argc, char const *argv[]) -> int { |
| 172 | - bool newCreation = not std::filesystem::exists("data.db"); | 172 | + auto appDirectory{ std::filesystem::path(argv[0])}; |
| | 173 | + std::cout << appDirectory.parent_path().string() << std::endl; |
| | 174 | + auto databasePath{ std::filesystem::path(appDirectory.parent_path().string() + "/data.db")}; |
| | 175 | + std::cout << databasePath.string() << std::endl; |
| | 176 | + bool newCreation = not std::filesystem::exists(databasePath.string()); |
| 173 | char *messageError; | 177 | char *messageError; |
| 174 | sqlite3 *database; | 178 | sqlite3 *database; |
| 175 | sqlite3_stmt *stmt; | 179 | sqlite3_stmt *stmt; |
| 176 | int exit = 0; | 180 | int exit = 0; |
| 177 | - exit = sqlite3_open("data.db", &database); | 181 | + exit = sqlite3_open(databasePath.c_str(), &database); |
| 178 | | 182 | |
| 179 | if (exit) { | 183 | if (exit) { |
| 180 | std::cerr << "Error opening database" << sqlite3_errmsg(database) | 184 | std::cerr << "Error opening database" << sqlite3_errmsg(database) |