juk3n/fluffypublic Fork
⑂ c47d640
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 finding proper path for database

Adrian Duraj committed 2024-06-26T13:32:48+02:00 Browse files
c47d640 parent: 1b488bf
modified src/main.cpp +6 -2
@@ -169,12 +169,16 @@ auto runConsoleApp(sqlite3* database) -> void {
169169 }
170170
171171 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());
173177 char *messageError;
174178 sqlite3 *database;
175179 sqlite3_stmt *stmt;
176180 int exit = 0;
177- exit = sqlite3_open("data.db", &database);
181+ exit = sqlite3_open(databasePath.c_str(), &database);
178182
179183 if (exit) {
180184 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)