是否有可能知道 QSqlQuery::bindValue 调用是否正常?
函数返回 void,我想知道为什么?至少应将缺少所需占位符的情况报告为错误 (ihmo)。
也许还有另一种可能性来检查绑定(bind)是否正确?
最佳答案
使用bindValue()并传递占位符名称或位置,它将返回已绑定(bind)的值,因此您将能够检查值是否已正确绑定(bind)。或者使用boundValues(),它将返回所有键和值的映射:
来自 Qt 文档的 boundValues() 示例
QMapIterator<QString, QVariant> i(query.boundValues());
while (i.hasNext()) {
i.next();
cout << i.key().toUtf8().data() << ": "
<< i.value().toString().toUtf8().data() << endl;
}
关于sql - 如何知道 QSqlQuery::bindValue 调用是否正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29847854/