bool Payment::checkUniqueIdentifier(const QString &invoice)
{
qDebug() << "entering Payment: check if the invoice has an associated unique identifier or not for the invoice=" + invoice;
QSqlQuery query(m_storageUserManager->database());
query.prepare("SELECT invoice FROM " + m_invoiceInfoTable + "WHERE invoice=:invoice");
query.bindValue(": invoice", invoice);
query.exec();
query.first();
bool tmp;
tmp = query.isValid();
return tmp;
}
嗨,这个布尔变量总是返回false,你能告诉我可能出现的问题吗? 我正在使用此功能如下
if(payment->checkUniqueIdentifier("invoice1"))
qDebug() << "It has a unique Identifier";
else
qDebug() << "It dont have a unique Identifier";
谢谢 问候, 普尼特
答案 0 :(得分:6)
查询中的位置之前没有空格。表名称和连接位置在哪里读取
SELECT invoice FROM m_invoiceInfoTableWHERE invoice=:invoice