I am familiar with the simple use of QSqlQuery::prepare()
and QSqlQuery::bindValue()
as in:
QSqlQuery query;
query.prepare("SELECT name, address FROM members WHERE id = :id");
query.bindValue(":id", member_id);
query.exec();
In this scenario I show a list of people (members) to the user, all with a check-box in front. The user can simply check which members to delete.
So now, the number of :id
are variable.
Currently, I solve this issue in quite a untidy fashion. All the id's checked people will be put in an array of integers called checked_items_ids
and then I simply for-loop that array:
QString prepare_query = QString("DELETE FROM members WHERE id = ").append(checked_items_ids[0]);
for(int i = 1; i < checked_items_ids.count(); i++)
prepare_query.append(QString(" OR id = %1").arg(checked_items_ids[i]));
QSqlQuery query(prepare_query);
query.exec();
Is there a 'tidier' way to do this? Using bindValue()
or anything that I might be overlooking?