PDA

View Full Version : Batch update fails with QSqlQuery



William Wilson
20th July 2007, 05:56
Qt version: 4.3.0
Platform: Win, MacOS, Linux
DB Engine: SqLite

The below batch update returns with "Parameter count mismatch" error.

QSqlQuery query1(Db);
query1.prepare("UPDATE TEST_TABLE SET (COL1, COL2) VALUES(?, ?) WHERE ID IN (3, 4)");

QVariantList qvParam1, qvParam2;
qvlParam1.push_back(300);
qvlParam1.push_back(300);

qvlParam2.push_back(1);
qvlParam2.push_back(1);

query1.addBindValue(qvParam1);
query1.addBindValue(qvlParam2);
if (!query1.execBatch())
{
qDebug() << "Failed to batch update" << query1.lastError();
assert(0);
return false;
}

Whereas a query like this works just fine in batch execution.
"INSERT INTO TEST_TABLE(COL1, COL2) VALUES(?, ?)"

Please help.

mm78
20th July 2007, 08:32
What does the call to prepare() return?

I think you probably would want to change the SQL statement to the following:


UPDATE TEST_TABLE SET COL1 = ?, COL2 = ? WHERE ID = ?

and bind a list of IDs as the third parameter.

William Wilson
20th July 2007, 15:36
Thank you.
The following query worked.
UPDATE TEST_TABLE SET COL1 = ?, COL2 = ? WHERE ID IN (3, 4)