Sql 布尔变量总是返回false bool付款::检查唯一标识符(常量字符串和发票) { qDebug()数据库()); 查询.准备(“从“+m_invoiceInfoTable+”中选择发票,其中发票=:发票”); 查询.bindValue(“:发票”,发票); exec(); query.first(); bool-tmp; tmp=query.isValid(); 返回tmp; }

Sql 布尔变量总是返回false bool付款::检查唯一标识符(常量字符串和发票) { qDebug()数据库()); 查询.准备(“从“+m_invoiceInfoTable+”中选择发票,其中发票=:发票”); 查询.bindValue(“:发票”,发票); exec(); query.first(); bool-tmp; tmp=query.isValid(); 返回tmp; },sql,boolean,Sql,Boolean,您好,这个布尔变量总是返回为false,您能告诉我可能出现什么问题吗 我使用这个函数如下 bool Payment::checkUniqueIdentifier(const QString &invoice) { qDebug() << "entering Payment: check if the invoice has an associated unique identifier or not for the invoice=" + invoice; QSqlQ

您好,这个布尔变量总是返回为false,您能告诉我可能出现什么问题吗 我使用这个函数如下

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;
}
if(付款->检查唯一标识符(“发票1”))

qDebug()在查询的where之前没有空格。表名和位置已连接并读取

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

查询中where之前没有空格。表名和位置已连接并读取

  if(payment->checkUniqueIdentifier("invoice1"))
    qDebug() << "It has a unique Identifier";
  else
    qDebug() << "It dont have a unique Identifier";
非常感谢:)这是一个愚蠢的错误,谢谢你这么快的回复:)非常感谢:)这是一个愚蠢的错误,谢谢你这么快的回复:)