summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--platform/default/mbgl/storage/offline_database.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/platform/default/mbgl/storage/offline_database.cpp b/platform/default/mbgl/storage/offline_database.cpp
index e1cd693662..43f7abaf9d 100644
--- a/platform/default/mbgl/storage/offline_database.cpp
+++ b/platform/default/mbgl/storage/offline_database.cpp
@@ -58,23 +58,36 @@ void OfflineDatabase::ensureSchema() {
removeExisting();
connect(ReadWrite | Create);
} catch (mapbox::sqlite::Exception& ex) {
- if (ex.code == SQLITE_CANTOPEN) {
- connect(ReadWrite | Create);
- } else if (ex.code == SQLITE_NOTADB) {
- removeExisting();
+ if (ex.code != SQLITE_CANTOPEN && ex.code != SQLITE_NOTADB) {
+ Log::Error(Event::Database, "Unexpected error connecting to database: %s", ex.what());
+ throw;
+ }
+
+ try {
+ if (ex.code == SQLITE_NOTADB) {
+ removeExisting();
+ }
connect(ReadWrite | Create);
+ } catch (...) {
+ Log::Error(Event::Database, "Unexpected error creating database: %s", util::toString(std::current_exception()).c_str());
+ throw;
}
}
}
- #include "offline_schema.cpp.include"
+ try {
+ #include "offline_schema.cpp.include"
- connect(ReadWrite | Create);
+ connect(ReadWrite | Create);
- // If you change the schema you must write a migration from the previous version.
- db->exec("PRAGMA auto_vacuum = INCREMENTAL");
- db->exec(schema);
- db->exec("PRAGMA user_version = 3");
+ // If you change the schema you must write a migration from the previous version.
+ db->exec("PRAGMA auto_vacuum = INCREMENTAL");
+ db->exec(schema);
+ db->exec("PRAGMA user_version = 3");
+ } catch (...) {
+ Log::Error(Event::Database, "Unexpected error creating database schema: %s", util::toString(std::current_exception()).c_str());
+ throw;
+ }
}
int OfflineDatabase::userVersion() {