Qsql查询检查qt中是否存在整数 [英] Qsql query to check whether integer is present or not in qt
问题描述
num是一个整数,PassID也是一个整数
qry.prepare(SELECT * FROM ISSUEPASS WHERE PassID = num);
我需要选择行PassID匹配的地方
我收到错误无法获取行没有查询
我尝试过:
qry.prepare(SELECT * FROM ISSUEPASS WHERE PassID = num);
您必须创建将num
作为参数传递给字符串格式化函数的查询字符串。因为 QSqlQuery :: prepare()| Qt SQL 5.10 [ ^ ]期望一个QString
参数,它可以在一个语句中完成:
qry.prepare(QString ( SELECT * FROM ISSUEPASS WHERE PassID =%1)。arg(num));
但是SQL命令绝不应该使用创建的文本字符串来避免SQL注入(这里没有文本参数也没关系)。首选解决方案是使用参数化查询:
qry.prepare( SELECT * FROM ISSUEPASS WHERE PassID =:passId);
qry.bindValue( :passId,num);
num is a integer and PassID also a integer
qry.prepare("SELECT * FROM ISSUEPASS WHERE PassID =num");
I need to select the row where the PassID matches
Iam getting error "unable to fetch row No query"
What I have tried:
qry.prepare("SELECT * FROM ISSUEPASS WHERE PassID =num");
You have to create the query string passingnum
as parameter to a string formatting function. Because QSqlQuery::prepare() | Qt SQL 5.10[^] expects aQString
argument, it can be be done in a single statement:
qry.prepare(QString("SELECT * FROM ISSUEPASS WHERE PassID =%1").arg(num));
But SQL commands should never use created text strings to avoid SQL injections (here it would be OK because there is no text parameter). The preferred solution is using parametrised queries:
qry.prepare("SELECT * FROM ISSUEPASS WHERE PassID =:passId"); qry.bindValue(":passId", num);
这篇关于Qsql查询检查qt中是否存在整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!