I have an interesting problem in Groovy. Hope someone can help me.
Basically I am using Groovy Sql. I need to select multiple tables in different databases. My second query depends on other query's, for example: "select * from table1-in-db1 where key = ${result-of-other-query1}
. Groovy works fine if I hardcode this in the function. However, my problem is the sql is defined in a xml file and after I retriev passed in into the the funciton as a string. it doesn't interperate the inline varialbe anymore, even I do have a variable called result-of-other-query1
in the scope.
Here is a piece of sudo code:
doQuery(String squery, String tquery) {
//query db1.
//squery = "select key1 from table1"
db1.rows(squery).each {row->
//query db2.
//tquery ="select * where myKey ='${row.key1}'"
println tquery
tdb.rows(tquery).each { row1 ->
.... // get error here, coz groovy did not replace ${row.key1}
}
}
}
Is there any way that I can tell Groovy to replace the inline variable even it is a passed in as a string?
Thanks a lot for your help in advance
Try
you may also want to consider using eachRow as opposed to rows.(query).each