C++ (Qt)QVariantList keys { QUuid("08a34f7d-7c20-4c58-a034-fba625ee11eb"), QUuid("96f86679-9b77-456d-8204-644e6f500d4c"), QUuid("a98c85b0-80b5-4a32-bb1f-7c3a7196cae8") }; const QString sqlText = R"(SELECT * FROM "TestTable" WHERE "Id" IN(?);)"; QSqlQuery select(m_database); select.prepare(sqlText); select.addBindValue(keys); if (!select.exec()) qDebug() << select.lastError().text();
SELECT * FROM "TestTable" WHERE "Id"::text IN(?);
SQLSELECT * FROM "TestTable" WHERE "Id" IN(SELECT unnest(string_to_array(?, ','))::uuid);
QSqlQuery query; query.prepare("INSERT INTO employee (id, name, salary) " "VALUES (:id, :name, :salary)"); query.bindValue(":id", 1001); query.bindValue(":name", "Thad Beaumont"); query.bindValue(":salary", 65000); query.exec();
C++ (Qt) QStringList keys; QString list = keys.join("','"); QString sql = "SELECT * FROM TestTable WHERE Id IN('"+list+"')"; QSqlQuery query(m_database); query.exec(sql); QSqlRecord rec = query.record(); while(query.next()){ QString id = query.value(rec.indexOf("id")).toString(); ... }
C++ (Qt)QStringList keys;foreach (QString param, http_post.uuids) { keys.append(sqlEscapeString(param));}// И только после экранирования можно так:QString list = keys.join("','");QString sql = "SELECT * FROM TestTable WHERE Id IN('"+list+"')"
SQLSELECT * FROM TABLE WHERE c1 = ? AND c2 = ? AND c3 = ?
C++ (Qt)QSqlQuery select("SELECT * FROM "TestTable" WHERE "Id" IN(SELECT unnest(string_to_array(?, ','))::uuid);");select.addBindValue(comma_separated_string);