From c28718b88b0cfc712a5177f04475813045c45119 Mon Sep 17 00:00:00 2001 From: Eric Lemanissier Date: Fri, 16 Jan 2015 11:44:59 +0100 Subject: Correction on bound values in case of repeated QSqlQuery::execBatch Until now, QSqlQuery::execBatch did not call resetBindCount, which lead the next call to QSqlQuery::addBindValue to start at non zero index. This is problematic in case of a prepared query which is called several times. Task-number: QTBUG-43874 Change-Id: I1a0f46e39b74d9538009967fd98a269e05aac6f2 Reviewed-by: Mark Brand --- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests/auto/sql/kernel') diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index a862ce2094..ecf3a9b050 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -147,6 +147,8 @@ private slots: void invalidQuery(); void batchExec_data() { generic_data(); } void batchExec(); + void QTBUG_43874_data() { generic_data(); } + void QTBUG_43874(); void oraArrayBind_data() { generic_data(); } void oraArrayBind(); void lastInsertId_data() { generic_data(); } @@ -338,6 +340,7 @@ void tst_QSqlQuery::dropTestTables( QSqlDatabase db ) << qTableName("blobstest", __FILE__, db) << qTableName("oraRowId", __FILE__, db) << qTableName("qtest_batch", __FILE__, db) + << qTableName("bug43874", __FILE__, db) << qTableName("bug6421", __FILE__, db).toUpper() << qTableName("bug5765", __FILE__, db) << qTableName("bug6852", __FILE__, db) @@ -2185,6 +2188,33 @@ void tst_QSqlQuery::batchExec() QVERIFY( q.value( 3 ).isNull() ); } +void tst_QSqlQuery::QTBUG_43874() +{ + QFETCH(QString, dbName); + QSqlDatabase db = QSqlDatabase::database(dbName); + CHECK_DATABASE(db); + + QSqlQuery q(db); + const QString tableName = qTableName("bug43874", __FILE__, db); + + QVERIFY_SQL(q, exec("CREATE TABLE " + tableName + " (id INT)")); + QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (id) VALUES (?)")); + + for (int i = 0; i < 2; ++i) { + QVariantList ids; + ids << i; + q.addBindValue(ids); + QVERIFY_SQL(q, execBatch()); + } + QVERIFY_SQL(q, exec("SELECT id FROM " + tableName + " ORDER BY id")); + + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 0); + + QVERIFY(q.next()); + QCOMPARE(q.value(0).toInt(), 1); +} + void tst_QSqlQuery::oraArrayBind() { QFETCH( QString, dbName ); -- cgit v1.2.3