[Zope-DB] changing from dtml-in

D. Rick Anderson ruger@comnett.net
Tue, 03 Dec 2002 18:21:00 -0800


Ok. I think I figured it out. It looks like you have to stuff all that 
you want returned into a single string and then 'return' it. Here's what 
I came up with:

x = context.basicReport()
final = ''
if x:
 for result in x:
  final = final + str(result.accid) + '<br>\n'

return final

Thanks for the help,

Rick


D. Rick Anderson wrote:

> Thanks for the reply Ed.  I tried that and here's how it looks:
> x = context.basicReport()
> if x:
> for result in x:
>  print result.accid
>
> where accid is the name of the first column in the table. It's still 
> not doing anything. If I call it from a DTML document with <dtml-var 
> query> I get a blank page with 'None' upin the left corner as if it's 
> returning an empty result. The query returns over 800 records when run 
> with the 'test' tab from the ZMI and I've run it in a <dtml-in> with 
> good results. I'm lost.
>
> Thanks,
>
> Rick
>
> Ed Leafe wrote:
>
>>
>> On Tuesday, December 3, 2002, at 07:36  PM, D. Rick Anderson wrote:
>>
>>> I've been using zope for quite some time, and I've always coded 
>>> almost completely in DTML. I know that I need to change and I'm 
>>> trying to make that jump right now. The 'fun' that I'm having is 
>>> calling an SQL query from a python script. Here's the basic code:
>>>
>>> x = context.basicReport()
>>> if x:
>>> for result in x:
>>>  print result
>>>
>>> where basicReport() is an SQL query that doesn't require any input 
>>> variables, but definitely returns data. When I test this code or 
>>> render it it does absolutely nothing. It doesn't even barf back an 
>>> error, it just doesn't do anything. I have some idle time on our 
>>> projects so I'd like to get this stuff nailed down.
>>
>>
>>
>>     In your example, 'result' is a row. You need to specify the field 
>> name:
>>
>> for result in x:
>>   print result.myfield
>>
>>
>>      ___/
>>     /
>>    __/
>>   /
>>  ____/
>>  Ed Leafe
>>  http://leafe.com/
>>  http://foxcentral.net
>>
>>
>>
>
>
> _______________________________________________
> Zope-DB mailing list
> Zope-DB@zope.org
> http://lists.zope.org/mailman/listinfo/zope-db
>