QtSql: execBatch() with SELECT statements
I am not an expert SQL user and I do not have much experience with the QtSql Module, I hope I am not missing something obvious:
I want to retrieve a list of blobs from my (sqlite) database with a batch command. But it does not work properly. isSelect() is not true for the query and I cannot get the results of the query.
Am I using the command correctly? Or should I simply do consecutive exec() commands. Will that have an effect on the speed?
Here is my sample code:
Code:
"SELECT my_blob_column FROM my_table WHERE id = ? ;"
);
q.prepare(query_string);
q.addBindValue(ids_in_qvariantlist);
if (!q.execBatch()) {...}
qDebug() << q.isSelect(); // is false
while (q.next()) { // is never true
qDebug() << q.value(0).toByteArray()
}
edit:
I am running Qt 4.5.3 on OpenSuse 11.2
Re: QtSql: execBatch() with SELECT statements
Why don't you build a list of the ids you want to retrieve. (I assume, that its not just all or some simple subset...)
Code:
for (int i=0;i < list.length();++i)
{
idset
+= QString::number(list.
at(i
));
if (i < list.length()-1)
idset += ",";
}
idset += ")";
q.exec("SELECT my_blob_column FROM my_table WHERE id in "+idset+";");
while (q.next())
{
}
..
HIH
Johannes
Re: QtSql: execBatch() with SELECT statements
Thank you Johannes,
I have tried using execBatch() so much that I did not see the obvious workaround :-)
Tobias