diff options
author | ComradeCrow <comradecrow@vivaldi.net> | 2023-04-24 13:40:06 -0700 |
---|---|---|
committer | ComradeCrow <comradecrow@vivaldi.net> | 2023-04-24 13:40:06 -0700 |
commit | 9af660d1fe3506ff129fbb62576a74ec20f9a5f2 (patch) | |
tree | bb19b9f3e70fca8abc7fcc1feba877841dfa0b26 /src | |
parent | 7ba81cbe9809cfb68bee85bc6f79e798ef7b05ce (diff) | |
download | ytcpp-9af660d1fe3506ff129fbb62576a74ec20f9a5f2.tar.gz |
hotfix
Diffstat (limited to 'src')
-rw-r--r-- | src/sqliteinterface.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/sqliteinterface.cpp b/src/sqliteinterface.cpp index 96e4020..1ae59be 100644 --- a/src/sqliteinterface.cpp +++ b/src/sqliteinterface.cpp @@ -2,25 +2,36 @@ #include <iostream> #include <cstring> #include <filesystem> +#include <stdexcept> #include "sqliteinterface.hpp" +namespace fs = std::filesystem; +using namespace std; + void openDB() { - sqlite3 *db; + fs::path appdata = DEF_APPDATA; + if ( ! fs::exists(appdata) ) { + error_code ec; + fs::create_directories(appdata, ec); + cout << ec << endl; + } + cout << fs::exists(appdata) << endl; + + sqlite3 *db; - char filename[] = DEF_APPDATA; - strcat(filename, "ytcpp.db"); - int rc = sqlite3_open(filename, &db); + fs::path filename = appdata / "ytcpp.db"; + int rc = sqlite3_open(filename.c_str(), &db); if( rc ) { char errmsg[] = "Can't open database: "; strcat(errmsg, sqlite3_errmsg(db)); - std::cerr << errmsg << std::endl; + throw runtime_error(errmsg); } else { std::cout << "Opened database successfully" << std::endl; - sqlite3_close(db); } + sqlite3_close(db); } \ No newline at end of file |