Details
-
Type:
Wish
-
Status:
Closed
-
Priority:
Trivial
-
Resolution: Fixed
-
Affects Version/s: 1.0-beta-1
-
Fix Version/s: 1.1-beta-2
-
Component/s: groovy-jdk, SQL processing
-
Labels:None
-
Environment:suse linux 10.0, jdk 1.6, but it probably affects all systems.
Description
I was not able to find a way to get sql metadata even when there are no rows returned
with the current Groovy sql stuff, so I subclassed groovy.sql.Sql and added a new
version of eachRow and rows such that each takes an additional "metaClosure" so
that I can feed the metaClosure the result set's meta data. that way, even if I don't have any
rows returned, I can be sure to have the meta data. And I don't have to
delve into the row processing closure to get the meta data from the first row
or anything like that.
I made my own subclass and added the following methods:
public List rows( final String sql,
final Closure metaClosure )
public void eachRow( final String sql,
final Closure metaClosure,
final Closure rowClosure )
So now I can:
def metaData
def results = sql.rows( query ) { metaData = it }
I didn't make a groovier version of the metadata class the way there's a
GroovyRowResult and GroovyResultSet class. I was very impressed with how
easy it was to do what I needed to do.
I have attached the methods I added, but they are not in the approved groovy format.
patch applied