Issue Details (XML | Word | Printable)

Key: GROOVY-730
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Guillaume Laforge
Reporter: Jean-Louis Berliet
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

Add the "oneRow" method to the groovy.sql.Sql class

Created: 13/Feb/05 03:09 PM   Updated: 23/Feb/05 05:09 PM   Resolved: 23/Feb/05 05:09 PM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.0-beta-10

Time Tracking:
Not Specified

File Attachments: 1. Text File patch2.txt (12 kB)
2. Text File patchOneRow.txt (11 kB)



 Description  « Hide

I want to add a "oneRow" method to the groovy.sql.Sql class.

So, instead of this :
answer = 0
sql.eachRow("select age from PERSON where firstName=James and lastName=Strachan") { row |
answer = row[0]
}

I could write something like :
result = sql.oneRow("select age from PERSON where firstName=James and lastName=Strachan").age

or like this :
result = sql.oneRow("select age from PERSON where firstName=James and lastName=Strachan")[0]



Jean-Louis Berliet added a comment - 13/Feb/05 03:14 PM

The patch i wrote to add the "oneRow" method.


Jean-Louis Berliet made changes - 13/Feb/05 03:14 PM
Field Original Value New Value
Attachment patchOneRow.txt [ 13971 ]
Guillaume Laforge made changes - 13/Feb/05 03:55 PM
Assignee Guillaume Laforge [ guillaume ]
james strachan added a comment - 14/Feb/05 04:02 AM

Just a thought.

how about adding a 'rows' method...

rows = sql.rows("select * from foo")
oneRow = rows[0]

as grabbing all of the rows into a list could be very handy in general?

Then oneRow (or is firstRow a better name) could be a trivial helper method for the above statement


Jean-Louis Berliet added a comment - 14/Feb/05 02:04 PM

I think you're right, James !


Jean-Louis Berliet added a comment - 19/Feb/05 06:28 AM

A new patch with "rows" and "firstRow" methods.


Jean-Louis Berliet made changes - 19/Feb/05 06:28 AM
Attachment patch2.txt [ 14005 ]
Guillaume Laforge added a comment - 23/Feb/05 05:09 PM

Patch applied, thank you Jean-Louis!


Guillaume Laforge made changes - 23/Feb/05 05:09 PM
Resolution Fixed [ 1 ]
Fix Version/s 1.0-beta-10 [ 11467 ]
Status Open [ 1 ] Closed [ 6 ]