Qt 6.11 is out! See what's new in the release
blog
MySql where variable IN (:values) and bindValue()
-
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); -
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 anINclause. 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.
-
S Seb Tur has marked this topic as solved on