diff --git a/src/sticker/Database.cxx b/src/sticker/Database.cxx index 67ca50fee..39d734789 100644 --- a/src/sticker/Database.cxx +++ b/src/sticker/Database.cxx @@ -67,11 +67,10 @@ static constexpr const char sticker_sql_create[] = " sticker_value ON sticker(type, uri, name);" ""; -StickerDatabase::StickerDatabase(Path path) - :db(NarrowPath(path)) +StickerDatabase::StickerDatabase(const char *_path) + :path(_path), + db(path.c_str()) { - assert(!path.IsNull()); - int ret; /* create the table and index */ @@ -91,6 +90,9 @@ StickerDatabase::StickerDatabase(Path path) } } +StickerDatabase::StickerDatabase(Path _path) + :StickerDatabase(NarrowPath{_path}) {} + StickerDatabase::~StickerDatabase() noexcept { if (db == nullptr) diff --git a/src/sticker/Database.hxx b/src/sticker/Database.hxx index e9d6dd804..512b9acd0 100644 --- a/src/sticker/Database.hxx +++ b/src/sticker/Database.hxx @@ -53,9 +53,13 @@ class StickerDatabase { SQL_COUNT }; + std::string path; + Sqlite::Database db; sqlite3_stmt *stmt[SQL_COUNT]; + explicit StickerDatabase(const char *_path); + public: /** * Opens the sticker database. @@ -68,6 +72,14 @@ public: StickerDatabase(StickerDatabase &&) noexcept = default; StickerDatabase &operator=(StickerDatabase &&) noexcept = default; + /** + * Open another connection to the same database file. + */ + [[nodiscard]] + StickerDatabase Reopen() const { + return StickerDatabase{path.c_str()}; + } + /** * Returns one value from an object's sticker record. Returns an * empty string if the value doesn't exist.