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

Antoine Muller Antoine.Muller@unine.ch
Tue, 11 Dec 2001 13:18:17 +0100


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.
- What is the representation of a ZSQL method results?
- How to put it in a python variable?
- How to access this variable?
I did try:
----BEGIN------
# 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.
data=context.GetOneQuestion(request)
print "data:", data
return printed
---END----
- Under certain not really understood conditions, is prints something
looking like a pointer adress.
- Somebody has a pointer on where to find a description for this
problem? I went through the Zope and there is no info about this or I
have not been able to deciphere it.

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>
------
 - Is it true that in a subDTMLMethod (a method called through a call
statement for example), one cannot use a <dtml-in> tag?
------
 - How do I send parameters to a dtml/sql method that are not necessarly
directly comming from the calling form?
At present I did this like:
------BEGIN-------
------ I put REQUEST and RESPONSE as parameters
---------------------
# 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

a=request.form['repchoisie']
# elimine les commentaires précédents
context.RemComment(request)
#elimine les réponses
context.RemReponse(request)
#insert les réponses
for i in range(len(a)):
     print i, a[i],
     request.set('rep_id',a[i]),
     context.AddReponse(request)
#insert le commentaire si il est de longueure non nule
if len(request.form['comment'])>0:
     context.AddComment(request)
#affiche la réponse
r=request.form['reg_id']
q=request.form['questions_id']
dir=request.URL1+'/ShowReponse?reg_id='+r+'&questions_id='+q
print dir
RESPONSE.redirect(dir)
#return printed
--------END--------
- Any more cannonical type of call that would do the same job.
- Any way to explicitely mention the parameter value in the call instead
of making some sort of global value.

- Any hint about how to avoid problem while using parameters like reg_id
encoded in a url. The workaround I found was to put in first position so
as to avoid that the interpreter transforms it into some &reg character.

Thanks a lot for your time.
AM
--
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