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 <mabrand@mabrand.nl>
This commit is contained in:
Eric Lemanissier 2015-01-16 11:44:59 +01:00 committed by Mark Brand
parent e01c8103e1
commit c28718b88b
2 changed files with 31 additions and 0 deletions

View File

@ -1060,6 +1060,7 @@ bool QSqlQuery::exec()
*/
bool QSqlQuery::execBatch(BatchExecutionMode mode)
{
d->sqlResult->resetBindCount();
return d->sqlResult->execBatch(mode == ValuesAsColumns);
}

View File

@ -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 );