sticker/Database: add method Reopen()

This commit is contained in:
Max Kellermann 2023-07-23 09:32:52 +02:00
parent dc31aa6a61
commit fbdd2324a5
2 changed files with 18 additions and 4 deletions

View File

@ -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)

View File

@ -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.