summaryrefslogtreecommitdiff
path: root/src/lib/dkdm_recipient_list.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-01-19 00:21:11 +0100
committerCarl Hetherington <cth@carlh.net>2025-01-22 14:34:25 +0100
commit16b3f6c6245acf9689349dbd2af7d4411f861767 (patch)
tree14bedff2389bf48c643e1a7d34c82d8265251801 /src/lib/dkdm_recipient_list.cc
parent9964a038c1a1ed86510439a33b7022807af31d8d (diff)
Move sqlite database open/close to a new SQLiteDatabase.
Diffstat (limited to 'src/lib/dkdm_recipient_list.cc')
-rw-r--r--src/lib/dkdm_recipient_list.cc48
1 files changed, 6 insertions, 42 deletions
diff --git a/src/lib/dkdm_recipient_list.cc b/src/lib/dkdm_recipient_list.cc
index f67379122..c57ade437 100644
--- a/src/lib/dkdm_recipient_list.cc
+++ b/src/lib/dkdm_recipient_list.cc
@@ -37,27 +37,21 @@ using boost::optional;
DKDMRecipientList::DKDMRecipientList()
: _dkdm_recipients("dkdm_recipients")
+ , _db(Config::instance()->dkdm_recipients_file())
{
- setup(Config::instance()->dkdm_recipients_file());
+ setup();
}
DKDMRecipientList::DKDMRecipientList(boost::filesystem::path db_file)
: _dkdm_recipients("dkdm_recipients")
+ , _db(db_file)
{
- setup(db_file);
+ setup();
}
-DKDMRecipientList::~DKDMRecipientList()
-{
- if (_db) {
- sqlite3_close(_db);
- }
-}
-
-
void
DKDMRecipientList::read_legacy_file(boost::filesystem::path xml_file)
{
@@ -105,48 +99,18 @@ DKDMRecipientList::read_legacy_document(cxml::Document const& doc)
void
-DKDMRecipientList::setup(boost::filesystem::path db_file)
+DKDMRecipientList::setup()
{
_dkdm_recipients.add_column("name", "TEXT");
_dkdm_recipients.add_column("notes", "TEXT");
_dkdm_recipients.add_column("recipient", "TEXT");
_dkdm_recipients.add_column("emails", "TEXT");
-#ifdef DCPOMATIC_WINDOWS
- auto rc = sqlite3_open16(db_file.c_str(), &_db);
-#else
- auto rc = sqlite3_open(db_file.c_str(), &_db);
-#endif
- if (rc != SQLITE_OK) {
- throw FileError("Could not open SQLite database", db_file);
- }
-
- sqlite3_busy_timeout(_db, 500);
-
SQLiteStatement screens(_db, _dkdm_recipients.create());
screens.execute();
}
-DKDMRecipientList::DKDMRecipientList(DKDMRecipientList&& other)
- : _dkdm_recipients(std::move(other._dkdm_recipients))
-{
- _db = other._db;
- other._db = nullptr;
-}
-
-
-DKDMRecipientList&
-DKDMRecipientList::operator=(DKDMRecipientList&& other)
-{
- if (this != &other) {
- _db = other._db;
- other._db = nullptr;
- }
- return *this;
-}
-
-
DKDMRecipientID
DKDMRecipientList::add_dkdm_recipient(DKDMRecipient const& dkdm_recipient)
{
@@ -159,7 +123,7 @@ DKDMRecipientList::add_dkdm_recipient(DKDMRecipient const& dkdm_recipient)
add_dkdm_recipient.execute();
- return sqlite3_last_insert_rowid(_db);
+ return sqlite3_last_insert_rowid(_db.db());
}