[Zope] PostgreSQL and external method

Thomas B. Passin tpassin@mitretek.org
Wed, 20 Jun 2001 16:46:14 -0400


[John VanDyk]
> I am trying to hook up a PostgreSQL database to Zope through an
> external method.
>
> Here's my method:
>
> def hello():
>      import sys
>      from pg import DB
>      conn = DB('demodb',user='skippy')
>      x = conn.query("SELECT * from testtable")
>      return x
>
> It works from the Python command line. But in my Zope page I get
>
> <pg query result>
>

It probably is working OK in Zope too.  Presumably conn.query() should
return a "query result", which would be some kind of structure, probably a
list.  It may know how to print itself, and perhaps that's what you saw when
you ran it from the command line (you don't say what the result was).

Probably this structure is a list of lists, or a list of dictionaries;
perhaps it is a class instance.  You ought to be able to find out in the
documentation, or just by trying things in python.  Once you know, it should
be easy to iterate through it in Zope.

Cheers,

Tom P