summaryrefslogtreecommitdiff
path: root/platform/qt
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2017-02-01 11:04:35 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2017-02-01 17:00:17 +0200
commitab814ef9b08e4b27204e7b64379cec78d46fc0ae (patch)
tree72b9efd2a123cee9c42ab03652deac91c2f3c263 /platform/qt
parent47b67fedb31117268efcde80aad4136704eaf714 (diff)
downloadqtlocation-mapboxgl-ab814ef9b08e4b27204e7b64379cec78d46fc0ae.tar.gz
[Qt] Guarantee QSqlDatabase connection name uniqueness
Guarantee QSqlDatabase connection name uniqueness by using a static counter together with the current thread.
Diffstat (limited to 'platform/qt')
-rw-r--r--platform/qt/src/sqlite3.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/platform/qt/src/sqlite3.cpp b/platform/qt/src/sqlite3.cpp
index 85de73e6fc..3470c36910 100644
--- a/platform/qt/src/sqlite3.cpp
+++ b/platform/qt/src/sqlite3.cpp
@@ -4,6 +4,7 @@
#include <QSqlError>
#include <QSqlQuery>
#include <QStringList>
+#include <QThread>
#include <QVariant>
#include <cassert>
@@ -52,10 +53,16 @@ void checkDatabaseError(const QSqlDatabase &db) {
class DatabaseImpl {
public:
DatabaseImpl(const char* filename, int flags) {
+ static uint64_t count = 0;
+ const QString connectionName = QString::number(uint64_t(QThread::currentThread())) + QString::number(count++);
+
if (!QSqlDatabase::drivers().contains("QSQLITE")) {
throw Exception { Exception::Code::CANTOPEN, "SQLite driver not found." };
}
- db.reset(new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", QString::number(qrand()))));
+
+ assert(!QSqlDatabase::contains(connectionName));
+ db.reset(new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE", connectionName)));
+
QString connectOptions = db->connectOptions();
if (flags & OpenFlag::ReadOnly) {
if (!connectOptions.isEmpty()) connectOptions.append(';');