diff options
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 || |