summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <tmpsantos@gmail.com>2017-07-14 16:39:42 +0300
committerThiago Marcos P. Santos <tmpsantos@gmail.com>2017-07-17 16:47:29 +0300
commitd9ad09ca364df52a316f644f908b7bb493093b48 (patch)
tree846dc8bea0ff7ddb3ec1b778af3b0113693c945e /platform
parentfdfd5f91f51f7185f731783ad8b2b4ff9c3e2f90 (diff)
downloadqtlocation-mapboxgl-d9ad09ca364df52a316f644f908b7bb493093b48.tar.gz
[Qt] Align database creation behavior with the default implementation
Qt doesn't throw a Exception::Code::CANTOPEN when trying to open a database that doesn't exist without the Create flag.
Diffstat (limited to 'platform')
-rw-r--r--platform/qt/src/sqlite3.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/platform/qt/src/sqlite3.cpp b/platform/qt/src/sqlite3.cpp
index 8df279c25d..6ed55c541f 100644
--- a/platform/qt/src/sqlite3.cpp
+++ b/platform/qt/src/sqlite3.cpp
@@ -50,6 +50,15 @@ void checkDatabaseError(const QSqlDatabase &db) {
}
}
+void checkDatabaseOpenError(const QSqlDatabase &db) {
+ // Assume every error when opening the data as CANTOPEN. Qt
+ // always returns -1 for `nativeErrorCode()` on database errors.
+ QSqlError lastError = db.lastError();
+ if (lastError.type() != QSqlError::NoError) {
+ throw Exception { Exception::Code::CANTOPEN, "Error opening the database." };
+ }
+}
+
class DatabaseImpl {
public:
DatabaseImpl(const char* filename, int flags) {
@@ -77,7 +86,7 @@ public:
db->setDatabaseName(QString(filename));
if (!db->open()) {
- checkDatabaseError(*db);
+ checkDatabaseOpenError(*db);
}
}
@@ -143,7 +152,7 @@ void Database::setBusyTimeout(std::chrono::milliseconds timeout) {
}
impl->db->setConnectOptions(connectOptions);
if (!impl->db->open()) {
- checkDatabaseError(*impl->db);
+ checkDatabaseOpenError(*impl->db);
}
}