Julian Clark wrote at 2003-11-26 17:07 +0800:
I'm trying to pass a result (or column of results) to a python script, within an SQL query.
Sounds impossible...
SELECT dealer_no, COUNT(mobile_no) as connects, entry_date FROM connects WHERE entry_date >= #2003/11/20# GROUP BY dealer_no, entry_date
where I'm wanting entry_date to be passed to a python script (and have the result returned as part of the sql query)
"entry_date" is a field in your database table. A Python script can only access this field through SQL (which is possible, e.g. using a second Z SQL method). When you call the script in the SQL code above, then the scripts result will affect the *SOURCE* for an SQL command but not its result.
... How Can I do something like this? ***************************** SELECT dealer_no, COUNT(mobile_no) as connects, <dtml-call to_month(entry_date)> FROM connects WHERE entry_date >= #2003/11/20# GROUP BY dealer_no, entry_date *****************************
###to_month return input.mm()
You do not call the python script inside the SQL but use a Python Script to postprocess the result. The easiest way is to call "to_month" on access to "entry_date". When you know the result set is small, you can also use something like transformedQuery(): r = context.mySQLMethod() for hit in r: r.entry_date = entry_date.mm() return r -- Dieter