summaryrefslogtreecommitdiffstats
path: root/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2018-03-01 06:45:45 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-03-27 16:50:19 +0000
commit7775eb248ac9cab0ea1e882889f00bec0efb178f (patch)
tree0c6a1b861fdf53eb82f2de1010ee8aa5b3601376 /src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
parentc2373fce3c112a0e497ab1de5dfe670ad8aa59c5 (diff)
sqlite: Support using execBatch() with duplicated named placeholders
Also expands the tst_qsqlquery::batchExec() test to account for this case and generally test the functionality. In addition it is made to be more robust to avoid any discrepencies with the testing data. The test in general is also cleaned up to enable more of it being tested with the different database drivers where possible. An expected fail is added for MySQL due to the fact that it has a bug where null timestamp entries are being converted to the current datetime when adding it as a bind value. Change-Id: I0061bd1c69ae35b4858afc49420f13ce59cf48ae Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp')
-rw-r--r--src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp b/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
index 91d2e9b205..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);