[Zope-DB] getting results from a ZSQL method in a python script
Antoine Muller
Antoine.Muller@unine.ch
Tue, 11 Dec 2001 16:07:18 +0100
Thanks for your time Dario but, on my system, the code you suggest returns:
An error was encountered while publishing this resource.
Error Type: AttributeError
Error Value: column
And if I remove the last line in the for loop:
------
# Example code:
# Import a standard function, and get the HTML request and response objects.
from Products.PythonScripts.standard import html_quote
request = container.REQUEST
RESPONSE = request.RESPONSE
# Return a string identifying this script.
request.set('questions_id',1),
data=context.GetOneQuestion(request)
for data_item in data:
print "data:", data_item
#print "data.col():", data_item.column
return printed
-----
I get: "data: <r instance at 8c7d780>"
Any idea to make it look like it should?
Cheers
AM
=?iso-8859-1?Q?Dario_Lopez-K=E4sten?= a écrit:
> 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.
>
> ----BEGIN------
> # Example code:
>
> # Return a string identifying this script.
> data=context.GetOneQuestion(request)
> for data_item in data:
> print "data:", data_item # the whole row
> print "data.col:", data_item.column
>
> return printed
>
> ---END----
>
> > - 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.
>
> hth,
>
> /dario
--
Antoine Muller Tel +41 878 803 041
Alpes Lasers Fax +41 878 803 042
2 r. de Champréveyres http://www.alpeslasers.ch
2008 Neuchâtel mailto:amuller@alpeslasers.ch