Qt QSqlQuery prepare和bindValue不工作 [英] Qt QSqlQuery prepare and bindValue not working
本文介绍了Qt QSqlQuery prepare和bindValue不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题与prepare和bindValue :(
I have a problem with prepare and bindValue :(
db.open();
QSqlQuery q;
q.prepare("SELECT id_malade,nom,prenom FROM Malade WHERE nom LIKE %:p% OR prenom = %:f% ;");
q.bindValue(":p",ui->lineEdit->text());
q.bindValue(":f",ui->lineEdit->text());
qDebug() << q.boundValue(0) << " " << q.boundValue(1);
qDebug() << q.executedQuery().toStdString().c_str(); db.close();
输出为:
QVariant(QString, "zit") QVariant(QString, "zit")
SELECT id_malade,nom,prenom FROM Malade WHERE nom LIKE %?% OR prenom = %?% ;
我试图更改:p和:f with?并在bindValue中使用int位置,但没有运气。
我在程序中使用了很多prepare和bindValue,它的工作正常问题只在这个类上:/
I tried to change :p and :f with ? and use int positions in bindValue but no luck. The query got executed with success so I couldn't fetch the exact error. I used prepare and bindValue a lot in my program and it works fine the problem is only on this class :/
推荐答案
而不是
[...] LIKE%:p%OR prenom =%:f%
您的准备语句应为
[...] nom LIKE'%'||:p ||'%'OR prenom ='%'||:f ||'%'
这篇关于Qt QSqlQuery prepare和bindValue不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文