Aliaspooryorik
ColdFusion ORM Book

Passing lists with named parameters and HQL

I've just been experimenting with passing lists into an HQL statement. I can get it to work with named parameters,but not with positional parameters.

This works:


result = ORMExecuteQuery( "from Art where id in (:list) and issold = :issold", {list=[1,2,3],issold=true} );

This doesn't (and I didn't expect it to):


result = ORMExecuteQuery( "from Art where id in (?) and issold = ?", [1,2,3,true] );

However, I would expect this to work which it doesn't:


result = ORMExecuteQuery( "from Art where id in (?) and issold = ?", [[1,2,3],true] );

I nearly always use named parameters, so this doesn't really bother me, but I feel the last example should work.

You could do this, but it seems a bit like a hack to me.


result = ORMExecuteQuery( "from Art where id in (?,?,?) and issold = ?", [1,2,3,true] );

2 comments

  1. Holy cow. I never knew even the first option was available. I'm embarrassed to say I was actually passing in multiple question marks for however many items were in the list. Thanks for the tip!

    Comment by Josh Curtiss – September 06, 2011
  2. @Josh - glad the post was useful :)

    Comment by John Whish – September 06, 2011

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.

Please subscribe me to any further comments
 

Search

Wish List

Found something helpful & want to say ’thanks‘? Then visit my Amazon Wish List :)

Categories

Recent Posts