我正在尝试像这样执行选择:
def queries = [
[
paramQuey: "",
mainQuery: "SELECT * FROM SOME_TABLE"
],
[
paramQuey: "SELECT SOME_COLUMN AS COUNT FROM A_TABLE WHERE SOMETHING=3",
mainQuery: "SELECT * FROM OTHER_TABLE WHERE ROWNUM<:COUNT"
]
]
queries.each {
def params = [:]
if(!it.paramQuery.isEmpty()) {
params = sql.firstRow(it.paramQuery)
}
sql.eachRow(mainQuery, params) { //<--here's my problem
//do something
}
}
但是,程序抛出
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: groovy.sql.Sql.eachRow() is applicable for argument types: (java.lang.String, java.util.LinkedHashMap, MyClass$_execute_closure4) values: [SELECT * FROM SOME_TABLE, [:], MyClass$_execute_closure4@b3600d]
Possible solutions: eachRow(java.lang.String, groovy.lang.Closure), eachRow(java.lang.String, groovy.lang.Closure, groovy.lang.Closure), eachRow(java.lang.String, java.util.List, groovy.lang.Closure), eachRow(groovy.lang.GString, groovy.lang.Closure), eachRow(groovy.lang.GString, groovy.lang.Closure, groovy.lang.Closure), eachRow(java.lang.String, int, int, groovy.lang.Closure)
这清楚地表明,没有任何方法可以使用命名参数来处理 eachRow。但是根据http://groovy.codehaus.org/api/groovy/sql/Sql.html有:
void eachRow(java.lang.String sql, java.util.Map params, Closure closure)
void eachRow(java.lang.String sql, java.util.Map params, Closure metaClosure, Closure rowClosure)
void eachRow(java.lang.String sql, java.util.Map map, Closure metaClosure, int offset, int maxRows, Closure rowClosure)
void eachRow(java.lang.String sql, java.util.Map params, int offset, int maxRows, Closure closure)
void eachRow(java.util.Map params, java.lang.String sql, Closure closure)
void eachRow(java.util.Map params, java.lang.String sql, Closure metaClosure, Closure rowClosure)
void eachRow(java.util.Map map, java.lang.String sql, Closure metaClosure, int offset, int maxRows, Closure rowClosure)
void eachRow(java.util.Map params, java.lang.String sql, int offset, int maxRows, Closure closure)
这让我想知道:我做错了什么,以及如何使用 eachRow 处理命名参数。