Question

Here is an example of what I am trying to do:

        def famlist = selection.getUnique('Family_code')

   ... Where “””...
    and testedWaferPass.family_code in $famlist
    “””...

famlist is a list of objects

‘selection’ will change every run, so the list is always changing.

I want to return only columns from my SQL search where the row is found in the list that I have created.

I realize it is supposed to look like: in ('foo','bar')

But no matter what I do, my list will not get like that. So I have to turn my list into a string?

('\${famlist.join("', '")}')

Ive tried the above, idk. Wasn’t working for me. Just thought I would throw that in there. Would love some suggestions. Thanks.

Was it helpful?

Solution

I am willing to bet there is a Groovier way to implement this than shown below - but this works. Here's the important part of my sample script. nameList original contains the string names. Need to quote each entry in the list, then string the [ and ] from the toString result. I tried passing as prepared statement but for that you need to dynamically create the string for the ? for each element in the list. This quick-hack doesn't use a prepared statement.

def nameList = ['Reports', 'Customer', 'Associates']
def nameListString = nameList.collect{"'${it}'"}.toString().substring(1)
nameListString = nameListString.substring(0, nameListString.length()-1)

String stmt = "select * from action_group_i18n where name in ( $nameListString)"
db.eachRow( stmt ) { row ->
    println  "$row.action_group_id, $row.language, $row.name"
} 

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top