Changeset View
Changeset View
Standalone View
Standalone View
runners/bookmarks/fetchsqlite.cpp
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Line(s) | |||||
91 | QList<QVariantMap> FetchSqlite::query(const QString &sql, QMap<QString, QVariant> bindObjects) | 91 | QList<QVariantMap> FetchSqlite::query(const QString &sql, QMap<QString, QVariant> bindObjects) | ||
92 | { | 92 | { | ||
93 | QMutexLocker lock(&m_mutex); | 93 | QMutexLocker lock(&m_mutex); | ||
94 | 94 | | |||
95 | auto db = openDbConnection(m_databaseFile); | 95 | auto db = openDbConnection(m_databaseFile); | ||
96 | 96 | | |||
97 | //qDebug() << "query: " << sql; | 97 | //qDebug() << "query: " << sql; | ||
98 | QSqlQuery query(db); | 98 | QSqlQuery query(db); | ||
99 | query.prepare(sql); | 99 | query.prepare(sql); | ||
100 | foreach(const QString &variableName, bindObjects.keys()) { | 100 | for (auto entry = bindObjects.constKeyValueBegin(); entry != bindObjects.constKeyValueEnd(); ++entry) { | ||
davidedmundson: There's an optimisation available here | |||||
This can be made much better by providing a custom range object to iterate from keyValueBegin() to keyValueEnd() - converting to std::map is quite inefficient. ivan: This can be made much better by providing a custom range object to iterate from `keyValueBegin… | |||||
101 | query.bindValue(variableName, bindObjects.value(variableName)); | 101 | query.bindValue((*entry).first, (*entry).second); | ||
ivan: `entry->first` and `entry->second` | |||||
102 | //qDebug() << "* Bound " << variableName << " to " << query.boundValue(variableName); | 102 | //qDebug() << "* Bound " << variableName << " to " << query.boundValue(variableName); | ||
103 | } | 103 | } | ||
104 | 104 | | |||
105 | if(!query.exec()) { | 105 | if(!query.exec()) { | ||
106 | QSqlError error = db.lastError(); | 106 | QSqlError error = db.lastError(); | ||
107 | //qDebug() << "query failed: " << error.text() << " (" << error.type() << ", " << error.number() << ")"; | 107 | //qDebug() << "query failed: " << error.text() << " (" << error.type() << ", " << error.number() << ")"; | ||
108 | //qDebug() << query.lastQuery(); | 108 | //qDebug() << query.lastQuery(); | ||
109 | } | 109 | } | ||
Show All 22 Lines |
There's an optimisation available here