I'm trying to parametrize a query that is currently working and is ripe for an SQL injection attack:
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);
}
}
I tried this, having the param without single quotes:
qryAwards = ORMExecuteQuery(
"from Award where awardID in (:awardList) and Game.Season.User.userID=:uid",
{awardList=form.deleteAwardList, uid=session.userID}
);
I keep getting the following error:
The value 117,118 cannot be converted to a number.
And this, with the param enclosed in single quotes:
qryAwards = ORMExecuteQuery(
"from Award where awardID in (':awardList') and Game.Season.User.userID=:uid",
{awardList=form.deleteAwardList, uid=session.userID}
);
Gets me the following error:
Invalid parameters specified for the query.
In HQL (which is what you use when you do ORMExecuteQuery()
) parameters used in an IN
clause need to be passed as an array. You need to convert form.deleteAwardList
to an array. There are a few different ways to handle this, but this will work.
qryAwards = ORMExecuteQuery(
"from Award where awardID in (:awardList) and Game.Season.User.userID=:uid",
{awardList=listToArray( form.deleteAwardList ), uid=session.userID}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With