diff options
| author | Carl Hetherington <cth@carlh.net> | 2025-01-19 00:21:11 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-01-22 14:34:25 +0100 |
| commit | 16b3f6c6245acf9689349dbd2af7d4411f861767 (patch) | |
| tree | 14bedff2389bf48c643e1a7d34c82d8265251801 /src/lib/cinema_list.cc | |
| parent | 9964a038c1a1ed86510439a33b7022807af31d8d (diff) | |
Move sqlite database open/close to a new SQLiteDatabase.
Diffstat (limited to 'src/lib/cinema_list.cc')
| -rw-r--r-- | src/lib/cinema_list.cc | 52 |
1 files changed, 7 insertions, 45 deletions
diff --git a/src/lib/cinema_list.cc b/src/lib/cinema_list.cc index e4095f1c4..4ee538efe 100644 --- a/src/lib/cinema_list.cc +++ b/src/lib/cinema_list.cc @@ -47,9 +47,10 @@ CinemaList::CinemaList() : _cinemas("cinemas") , _screens("screens") , _trusted_devices("trusted_devices") + , _db(Config::instance()->cinemas_file()) { setup_tables(); - setup(Config::instance()->cinemas_file()); + setup(); } @@ -57,9 +58,10 @@ CinemaList::CinemaList(boost::filesystem::path db_file) : _cinemas("cinemas") , _screens("screens") , _trusted_devices("trusted_devices") + , _db(db_file) { setup_tables(); - setup(db_file); + setup(); } @@ -161,19 +163,8 @@ CinemaList::clear() void -CinemaList::setup(boost::filesystem::path db_file) +CinemaList::setup() { -#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 cinemas(_db, _cinemas.create()); cinemas.execute(); @@ -185,27 +176,6 @@ CinemaList::setup(boost::filesystem::path db_file) } -CinemaList::CinemaList(CinemaList&& other) - : _db(other._db) - , _cinemas(std::move(other._cinemas)) - , _screens(std::move(other._screens)) - , _trusted_devices(std::move(other._trusted_devices)) -{ - other._db = nullptr; -} - - -CinemaList& -CinemaList::operator=(CinemaList&& other) -{ - if (this != &other) { - _db = other._db; - other._db = nullptr; - } - return *this; -} - - CinemaID CinemaList::add_cinema(Cinema const& cinema) { @@ -219,7 +189,7 @@ CinemaList::add_cinema(Cinema const& cinema) statement.execute(); - return sqlite3_last_insert_rowid(_db); + return sqlite3_last_insert_rowid(_db.db()); } @@ -248,14 +218,6 @@ CinemaList::remove_cinema(CinemaID id) } -CinemaList::~CinemaList() -{ - if (_db) { - sqlite3_close(_db); - } -} - - static vector<pair<CinemaID, Cinema>> cinemas_from_result(SQLiteStatement& statement) @@ -314,7 +276,7 @@ CinemaList::add_screen(CinemaID cinema_id, dcpomatic::Screen const& screen) add_screen.execute(); - auto const screen_id = sqlite3_last_insert_rowid(_db); + auto const screen_id = sqlite3_last_insert_rowid(_db.db()); for (auto device: screen.trusted_devices) { SQLiteStatement add_device(_db, _trusted_devices.insert()); |
