使用 where in 子句参数化 ORM 查询
Parameterize ORM query with where in clause
我正在尝试参数化一个查询,该查询当前正在运行并且已经成熟 SQL 注入攻击:
qryAwards = ORMExecuteQuery(
"from Award where awardID in (#form.deleteAwardList#) and Game.Season.User.userID=:uid",
{uid=session.userID}
);
if(not isNull(qryAwards) and arrayLen(qryAwards)){
for(i in qryAwards){
entityDelete(i);
}
}
我试过了,参数没有单引号:
qryAwards = ORMExecuteQuery(
"from Award where awardID in (:awardList) and Game.Season.User.userID=:uid",
{awardList=form.deleteAwardList, uid=session.userID}
);
我不断收到以下错误:
The value 117,118 cannot be converted to a number.
还有这个,参数用单引号括起来:
qryAwards = ORMExecuteQuery(
"from Award where awardID in (':awardList') and Game.Season.User.userID=:uid",
{awardList=form.deleteAwardList, uid=session.userID}
);
出现以下错误:
Invalid parameters specified for the query.
在 HQL 中(这是您在执行 ORMExecuteQuery()
时使用的),IN
子句中使用的参数需要作为数组传递。您需要将 form.deleteAwardList
转换为数组。有几种不同的方法来处理这个问题,但这行得通。
qryAwards = ORMExecuteQuery(
"from Award where awardID in (:awardList) and Game.Season.User.userID=:uid",
{awardList=listToArray( form.deleteAwardList ), uid=session.userID}
);
我正在尝试参数化一个查询,该查询当前正在运行并且已经成熟 SQL 注入攻击:
qryAwards = ORMExecuteQuery(
"from Award where awardID in (#form.deleteAwardList#) and Game.Season.User.userID=:uid",
{uid=session.userID}
);
if(not isNull(qryAwards) and arrayLen(qryAwards)){
for(i in qryAwards){
entityDelete(i);
}
}
我试过了,参数没有单引号:
qryAwards = ORMExecuteQuery(
"from Award where awardID in (:awardList) and Game.Season.User.userID=:uid",
{awardList=form.deleteAwardList, uid=session.userID}
);
我不断收到以下错误:
The value 117,118 cannot be converted to a number.
还有这个,参数用单引号括起来:
qryAwards = ORMExecuteQuery(
"from Award where awardID in (':awardList') and Game.Season.User.userID=:uid",
{awardList=form.deleteAwardList, uid=session.userID}
);
出现以下错误:
Invalid parameters specified for the query.
在 HQL 中(这是您在执行 ORMExecuteQuery()
时使用的),IN
子句中使用的参数需要作为数组传递。您需要将 form.deleteAwardList
转换为数组。有几种不同的方法来处理这个问题,但这行得通。
qryAwards = ORMExecuteQuery(
"from Award where awardID in (:awardList) and Game.Season.User.userID=:uid",
{awardList=listToArray( form.deleteAwardList ), uid=session.userID}
);