SRombauts / SQLiteCpp

SQLiteC++ (SQLiteCpp) is a smart and easy to use C++ SQLite3 wrapper.
http://srombauts.github.io/SQLiteCpp
MIT License
2.19k stars 509 forks source link

If the provided filename contains directories or path segments, the database will not be created. #465

Closed tanoDxyz closed 4 months ago

tanoDxyz commented 5 months ago

SQLite::Database(databaseName, SQLite::OPEN_CREATE | SQLite::OPEN_READWRITE)); SQLite::Database(std::filesystem::path("/a/b/abc.db"), SQLite::OPEN_CREATE | SQLite::OPEN_READWRITE);

Whenever i tried to create database on disk and provides a path (relative or absolute) and the directory(s) does not exists i got the following error.

terminate called after throwing an instance of 'SQLite::Exception' what(): unable to open database file

i have to create directory manually.

I am not sure if i am missing something or library behaves in that manner.

I am using clion with mingw and of course windows.

UnixY2K commented 4 months ago

I think this is expected behavior, as sqlite behaves this way. you should check the existence of an directory before creating any file, if it does not exist create the directory.

for this you can use std::filesystem::create_directories so it creates recursively the directory for you