Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.7-beta-2
-
None
-
Any
-
Patch
Description
All java.sql.ResultSetMetaData methods (except for getColumnCount()) take a column index. This makes for awkward use in groovy.sql.Sql:
metaClosure = {ResultSetMetaData metaData -> vals = [] for (i in 1..metaData.columnCount) { vals << metaData.getColumnName(i) } // do something with column names ... }
It would be nicer to be able to do this:
metaClosure = {ResultSetMetaData metaData ->
vals = metaData*.columnName
// do something with column names ...
}
The attached patch achieves this by adding an iterator() method to ResultSetMetaData in SqlGroovyMethods.
Apply the patch like this:
patch -p1 -i resultsetmeta-iteration.patch
I've also added assertions to test this functionality into the existing tests for the metadata closure handling.
One thing I'm not sure I've got right is the handling of dynamic methods and properties, and exceptions, in ResultSetMetaDataWrapper. Also, I don't know if I might have missed some convenience methods that might have saved some code. Feedback welcome.
Finally, I don't know whether you would want to include this in 1.7, because that's supposed to be feature-complete. If not, perhaps it could be added for a future version?
John Hurst