Issue Details (XML | Word | Printable)

Key: GROOVY-1109
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Jochen Theodorou
Reporter: Dierk Koenig
Votes: 0
Watchers: 3
Operations

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

provide method rows() and firstRow() on groovy.sql.DataSet

Created: 01/Nov/05 01:19 PM   Updated: 28/Jun/07 09:53 PM
Component/s: None
Affects Version/s: 1.0-JSR-3
Fix Version/s: 1.1-beta-2

Time Tracking:
Not Specified

File Attachments: 1. Text File DataSet.txt (3 kB)
2. Text File DataSetV2.txt (2 kB)
3. Text File SqlCompleteTest.txt (1 kB)



 Description  « Hide
allow
data = new groovy.sql.DataSet(tablename)
List rows = data.rows()
to fetch all rows at once analogous to Sql.rows(...)

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
John Carnell added a comment - 24/Mar/07 08:19 PM
Added two patches for the proposed enhancement to the DataSet class. I have added the rows() method
and the firstRow() method. I have also updated the SqlCompleteTest class to test these two methods.

However, I do have a question on this open improvement. The way I read the "improvement" is that the rows() method
will return all of the rows on the underlying tableset. To implement this I simply did a SELECT * FROM the table to
build the data. However, what happens if the user is trying to filter based on a where. Shouldn't the call really return all of the rows for the DataSet.

Please let me know how exactly this code should work. I can change the code to behave whatever way needed.


John Carnell added a comment - 26/Mar/07 09:35 PM
Came to the realization that I could just re-use the rows() method on the SQL class and just pass in a SQL
string. D**mba@@ to go and cut-and paste code. I uploaded the revised dataset class. The changes still work and the unit tests pass.

Jochen Theodorou added a comment - 26/Apr/07 01:51 PM
implemented

Paul King added a comment - 28/Jun/07 09:07 PM
I think John Carnell's query is an important one here:

"... However, what happens if the user is trying to filter based on a where. Shouldn't the call really return all of the rows for the DataSet."

I think the answer to this is yes.

Here is some code:

def athletes = [
    [firstname: 'Paul', lastname:'Tergat', dateOfBirth:'1969-06-17'],
    [firstname: 'Khalid', lastname:'Khannouchi', dateOfBirth:'1971-12-22'],
    [firstname: 'Ronaldo', lastname:'da Costa', dateOfBirth:'1970-06-07'],
    [firstname: 'Paula', lastname:'Radcliffe', dateOfBirth:'1973-12-17']
]

athleteSet = db.dataSet('Athlete')
athletes.each { a -> athleteSet.add(a) }
youngsters = athleteSet.findAll{ it.dateOfBirth > '1970-1-1'}
def rows = []
youngsters.each { rows += it.lastname }
println rows.join(', ')           // => Khannouchi, da Costa, Radcliffe
println youngsters.rows().size()  // => 4

I would expect rows() for youngsters to return the three youngster rows not the entire original table (4 rows here).


Jochen Theodorou added a comment - 28/Jun/07 09:24 PM
do I see it right, that we just need to replace
public List rows() throws SQLException {
        String sql  = "SELECT * FROM " + table;
        return rows(sql);

    }

with

public List rows() throws SQLException {
        String sql  = getSql();
        return rows(sql);
    }

in DataSet?


Paul King added a comment - 28/Jun/07 09:29 PM
Fixed

Paul King added a comment - 28/Jun/07 09:53 PM
Thought you would have already clocked off, so went ahead and fixed it.

Yes, your suggestion was almost what I did - just:

rows(getSql(), getParameters())

because sql is stored proc with params.