diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-02-19 13:22:24 +0100 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2019-03-13 18:28:04 +0100 |
commit | 3f7b70fdb0e40d0cbbaea17505878c72491e3cd2 (patch) | |
tree | dbbc7be080142263797bafbff5c4b950c615dc90 /platform/default/src/mbgl/storage/offline_database.cpp | |
parent | 5e58a0d81d702a543e898b489ead044a630229a0 (diff) | |
download | qtlocation-mapboxgl-3f7b70fdb0e40d0cbbaea17505878c72491e3cd2.tar.gz |
[core] expose an option to change the db file path in runtime
Diffstat (limited to 'platform/default/src/mbgl/storage/offline_database.cpp')
-rw-r--r-- | platform/default/src/mbgl/storage/offline_database.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp index 7732076991..752f5ac20a 100644 --- a/platform/default/src/mbgl/storage/offline_database.cpp +++ b/platform/default/src/mbgl/storage/offline_database.cpp @@ -27,16 +27,7 @@ OfflineDatabase::OfflineDatabase(std::string path_, uint64_t maximumCacheSize_) } OfflineDatabase::~OfflineDatabase() { - // Deleting these SQLite objects may result in exceptions, but we're in a destructor, so we - // can't throw anything. - try { - statements.clear(); - db.reset(); - } catch (const util::IOException& ex) { - handleError(ex, "close database"); - } catch (const mapbox::sqlite::Exception& ex) { - handleError(ex, "close database"); - } + cleanup(); } void OfflineDatabase::initialize() { @@ -78,6 +69,25 @@ void OfflineDatabase::initialize() { } } +void OfflineDatabase::changePath(const std::string& path_) { + Log::Info(Event::Database, "Changing the database path."); + cleanup(); + path = path_; + initialize(); +} + +void OfflineDatabase::cleanup() { + // Deleting these SQLite objects may result in exceptions + try { + statements.clear(); + db.reset(); + } catch (const util::IOException& ex) { + handleError(ex, "close database"); + } catch (const mapbox::sqlite::Exception& ex) { + handleError(ex, "close database"); + } +} + void OfflineDatabase::handleError(const mapbox::sqlite::Exception& ex, const char* action) { if (ex.code == mapbox::sqlite::ResultCode::NotADB || ex.code == mapbox::sqlite::ResultCode::Corrupt || |