MySql where variable IN (:values) and bindValue()
Solved
General and Desktop
-
Would it be possible to pass :values i na bindVaule?
something like below does not work.
when i tried to bind myIds directly it fails tooQString myIds = "1, 12, 13, 14, 15, 16, 2, 3, 4, 7, 8, 9"; // Split the string into a QStringList QStringList idsList = myIds.split(", "); // Convert QStringList to QVariantList QVariantList idsVariantList; for (const QString &id : idsList) { idsVariantList.append(id.toInt()); } // Bind the QVariantList to the query query.prepare("SELECT * FROM table WHERE id IN (:myIds)"); query.bindValue(":myIds", idsVariantList);
-
@Seb-Tur
You will find that you cannot bind to the list of values for anIN
clause. Not supported by the driver.I think you would have to produce the actual
IN ( ..., ... )
as a string for the query. Doubtless with caveats about injection.There may be MySQL possibilities to work around this, I don't know.
-