布尔变量总是返回false

Pun*_*eet 0 sql boolean

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;
}
Run Code Online (Sandbox Code Playgroud)

嗨,这个布尔变量总是返回false,你能告诉我可能出现的问题是我使用这个函数,如下所示

  if(payment->checkUniqueIdentifier("invoice1"))
    qDebug() << "It has a unique Identifier";
  else
    qDebug() << "It dont have a unique Identifier";
Run Code Online (Sandbox Code Playgroud)

Puneet,谢谢你

Ben*_*Ben 6

在查询中的位置之前没有空格.表名和连接的位置和读取的位置

SELECT invoice FROM m_invoiceInfoTableWHERE invoice=:invoice
Run Code Online (Sandbox Code Playgroud)