I found it really cool that in Groovy SQL it is possible to do this:
def resultList = Domain.executeQuery('select * from languages where name = :name', [name: 'Groovy'])
I am trying to get the HQL "in" keyword to work with a dynamic list used as the argument, not a fixed list.
I also know that you can use the "?" operator for your SQL parameters instead of using named parameters. However according to this question:
Doing an "IN" query with Hibernate
The "in" keyword only supports named and positional parameters, not the "?" parameter. The problem is, when I try to do something like this:
def paramMap = [:]
paramMap.put("name", "groovy")
def resultList = Domain.executeQuery('select * from languages where name = :name', paramMap)
I get an error saying that I have not specified the parameter name. So it is acting as if I have not actually specified the parameter "name". I have read the Groovy documentation on named parameters here:
http://groovy.codehaus.org/api/groovy/sql/Sql.html
But all of the examples using named parameters use a predefined parameter list. I have searched and have not found an example of using a dynamic parameter list map. How can I pass a dynamic map of parameters into Groovy named SQL query? If that is not possible, how can I use the "in" keyword with a dynamic list?
To be clear, I am constructing a dynamic SQL query and I would like to be able to add parameters to a map or list as I go along. I was previously using the "?" operator until I had to use the "in" clause, which does not work with "?".