[Zope-DB] Retrieving Data from Z SQL in Python

Christer Fernstrom myzope at fernstromOnThe.net
Thu May 19 16:26:35 EDT 2005


----- Original Message ----- 
From: "Cliff Ford" <Cliff.Ford at ed.ac.uk>
To: "Christer Fernstrom" <myzope at fernstromOnThe.net>
Cc: <zope-db at zope.org>
Sent: Thursday, May 19, 2005 8:16 AM
Subject: Re: [Zope-DB] Retrieving Data from Z SQL in Python


>
> Christer Fernstrom wrote:
>> Hello,
>>
>> I have a very simple Z SQL method that works fine when I test run it. But
>> when I call it from a Python script (see below) and attempt to print the
>> result, I get the following error:
>>
>> Error Type: TypeError
>> Error Value: cannot concatenate 'str' and 'ImplicitAcquirerWrapper' 
>> objects
>>
>> ------ Python script -----
>> # 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
>>
>> data = context.getChunk1()
>> for data_row in data:
>>  print "data-row="+data_row
>> return printed
>
> You need to iterate over the columns in the row:
>
> data = context.getChunk1()
> for data_row in data:
>   print "data-row="
>   for item in data_row:
>     print item + ' '
> return printed
>
> It is more normal to fetch one result row at a time:
>
> for data_row in context.getChunk1():
>     # and handle the results by column name
>     print data_row.FirstName
>     print ' '
>     print data_row.Surname
>     ...
> return printed
>
> HTH
>
> Cliff
>

Thanks Cliff. What you propose works fine!
-- christer



More information about the Zope-DB mailing list