Z SQL method results from a python script
I have a Z SQL method named "employ_data" as below: SELECT SUM(employ_hour) AS sum_hour, SUM(employ_salary+employ_hour) AS sum_total, division WHERE employ_record.month=<dtml-sqlvar month type=string> AND employ_record.year=<dtml-sqlvar year type=int> GROUP BY division This method has been tested and returns multiple rows in the result set correctly with input for month, year. I want to use this method in a python script but can't for the life of me get it to return the entire result set. Python script: results = context.employ_data(month=month, year=year) for result in results: return result.sum_hour, result.sum_total, result.division This returns only one record -- the first record in the result set. I need the entire result set. Am I misusing this or have incorrect script? Thanks, Daniel
[<daniel.a.fulton@delphiauto.com>]
I want to use this method in a python script but can't for the life of me
get it
to return the entire result set.
Python script:
results = context.employ_data(month=month, year=year)
for result in results: return result.sum_hour, result.sum_total, result.division
This returns only one record -- the first record in the result set. I need the entire result set.
The "return" statement causes the function to end and return the result. So you only get the first row. You should build the results into a list, then return the list. rows=[] for result in results: rows.append( (result.sum_hour, result.sum_total)) return rows Each row is now a tuple containing the hour and sum. Cheers, Tom P
participants (2)
-
daniel.a.fulton@delphiauto.com -
Thomas B. Passin