This code returns no records:
QString sql = QString("SELECT * FROM %1 WHERE dd_nomdest LIKE '%:machine';").arg(TABLE_NEW_ORDERS);
QSqlQuery query(_db);
if (!query.prepare(sql))
{
qWarning() << ID << "Prepare query failed" << sql;
qWarning() << ID << query.lastError();
return false;
}
query.bindValue(":machine", machine);
qDebug() << query.boundValues();
while (query.next())
{
// do stuff
}
prepare
and exec
return true
.
boundValues
return an empty list.
The machine
variables contains the expected value.
If I compose the SQL string using the QString
placeholder (instead of binding values) the query works as expected.
Where is the error in my syntax?
Qt 6.2.0, Ubuntu 21.10, SQL Server.