diff options
Diffstat (limited to 'src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp')
-rw-r--r-- | src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp index cb3d905f46..6375825720 100644 --- a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp +++ b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp @@ -56,6 +56,7 @@ #include <qregularexpression.h> #endif #include <QTimeZone> +#include <QScopedValueRollback> #if defined Q_OS_WIN # include <qt_windows.h> @@ -129,6 +130,7 @@ protected: bool gotoNext(QSqlCachedResult::ValueCache& row, int idx) override; bool reset(const QString &query) override; bool prepare(const QString &query) override; + bool execBatch(bool arrayBind) override; bool exec() override; int size() override; int numRowsAffected() override; @@ -443,6 +445,29 @@ static QString timespecToString(const QDateTime &dateTime) } } +bool QSQLiteResult::execBatch(bool arrayBind) +{ + Q_UNUSED(arrayBind); + Q_D(QSqlResult); + QScopedValueRollback<QVector<QVariant>> valuesScope(d->values); + QVector<QVariant> values = d->values; + if (values.count() == 0) + return false; + + for (int i = 0; i < values.at(0).toList().count(); ++i) { + d->values.clear(); + QScopedValueRollback<QHash<QString, QVector<int>>> indexesScope(d->indexes); + QHash<QString, QVector<int>>::const_iterator it = d->indexes.constBegin(); + while (it != d->indexes.constEnd()) { + bindValue(it.key(), values.at(it.value().first()).toList().at(i), QSql::In); + ++it; + } + if (!exec()) + return false; + } + return true; +} + bool QSQLiteResult::exec() { Q_D(QSQLiteResult); @@ -471,7 +496,7 @@ bool QSQLiteResult::exec() // can end up in a case where for virtual tables it returns 0 even though it // has parameters if (paramCount > 1 && paramCount < values.count()) { - const auto countIndexes = [](int counter, const QList<int>& indexList) { + const auto countIndexes = [](int counter, const QVector<int> &indexList) { return counter + indexList.length(); }; @@ -485,13 +510,14 @@ bool QSQLiteResult::exec() // placeholders. So we need to ensure the QVector has only one instance of // each value as SQLite will do the rest for us. QVector<QVariant> prunedValues; - QList<int> handledIndexes; + QVector<int> handledIndexes; for (int i = 0, currentIndex = 0; i < values.size(); ++i) { if (handledIndexes.contains(i)) continue; const auto placeHolder = QString::fromUtf8(sqlite3_bind_parameter_name(d->stmt, currentIndex + 1)); - handledIndexes << d->indexes[placeHolder]; - prunedValues << values.at(d->indexes[placeHolder].first()); + const auto &indexes = d->indexes.value(placeHolder); + handledIndexes << indexes; + prunedValues << values.at(indexes.first()); ++currentIndex; } values = prunedValues; |