groovy

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

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.0-beta-10
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    2

Description

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]

  1. patch2.txt
    19/Feb/05 6:28 AM
    12 kB
    Jean-Louis Berliet
  2. patchOneRow.txt
    13/Feb/05 3:14 PM
    11 kB
    Jean-Louis Berliet

Activity

Hide
Jean-Louis Berliet added a comment -

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

Show
Jean-Louis Berliet added a comment - The patch i wrote to add the "oneRow" method.
Hide
james strachan added a comment -

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

Show
james strachan added a comment - 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
Hide
Jean-Louis Berliet added a comment -

I think you're right, James !

Show
Jean-Louis Berliet added a comment - I think you're right, James !
Hide
Jean-Louis Berliet added a comment -

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

Show
Jean-Louis Berliet added a comment - A new patch with "rows" and "firstRow" methods.
Hide
Guillaume Laforge added a comment -

Patch applied, thank you Jean-Louis!

Show
Guillaume Laforge added a comment - Patch applied, thank you Jean-Louis!

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: