[Zope-DB] getting results from a ZSQL method in a python script

Dario Lopez-Kästen dario@ita.chalmers.se
Tue, 11 Dec 2001 13:56:16 +0100

Subject: [Zope-DB] getting results from a ZSQL method in a python script

> Hello list,
> I need help on the following subject, I have been able to call a ZSQL
> method from a Python script, I have probably been able to transmit it
> parameters but I have no idea how to get the results.

first thing to remember is that SQL alwyas return a list of rows.

# Example code:

# Return a string identifying this script.
for data_item in data:
   print "data:", data_item # the whole row
   print "data.col:", data_item.column

return printed


> - Under certain not really understood conditions, is prints something
> looking like a pointer adress.

it prints the returned object instance :-). this should be described in the
Zope Book i would think...

> As I write, I'll use this opportunity to ask all my questions:
>  - Is it true that the dtml-in tag cannot be nested like
> -----
> <dtml-in aZSQLMethodThatGetsParameterLikeInfo>
>   <dtml-in
> aZSQLMethodThatGetsDataLikeInfoDependingOnTheParametersForTheSQLRequest>
>    some presentation...
>   </dtml-in>
> </dtml-in>
> ------

do you pass your parameters explicitly to the second SQL? or are they
obtqined thru acqiusition?

>  - Is it true that in a subDTMLMethod (a method called through a call
> statement for example), one cannot use a <dtml-in> tag?

we do this often

<dtml-call "REQUEST.set('results', sql_method(param1=somtehing, ...)">

then we have it in the REQUEST and cad stuff like <dtml-in name="results"
....>. I think it works best when you do a <dtml-var your_dtml-methodhere>
after setting the results var...

some of the other stuff are covered in the Zope Book.