[Zope] connet to MS-SQL database with ython script from with in zope

Tim Hicks tim@sitefusion.co.uk
Mon, 18 Feb 2002 19:20:28 -0000


> Hi Tim,
> I did exactly as you told me to do. The following is the python script
>
>          sql="Select * from LinkArea"
>          results = container.sql_method(the_sql=sql)
>          for i in results:
>               print i
>          return printed
>
> and below is the ZSQL method:
> <dtml-var the_sql>
>
> when i do this, it gives me the instances, something like this..
> <r instance at 01674978>
> <r instance at 015DAED0>
> <r instance at 01674978>
> <r instance at 015DAED0>
>
> I do not understand this.

ZSQL methods return special objects ('pluggable brains' I believe they are
called - I'm sure someone will correct me if I'm wrong).  Try this to see
how to use them from python scripts (dtml docs/methods have some magic that
makes it easy transparent)...

-------
sql="Select * from LinkArea"
results = container.sql_method(the_sql=sql)
headings = results.names() # names() gives you the column headings
print headings
for row in results:
    for heading in headings:
        print row[heading]
return printed
--------

There's also a dictionaries() method on the result object that is very
helpful.  I know there are more posts on this in the list archives as well.

hth

tim