[Zope-DB] psycopg in python script

Charlie Clark charlie at egenix.com
Fri Feb 24 05:45:54 EST 2006

On 2006-02-23 at 21:36:46 [+0100], garry <garry at schoolteachers.co.uk> wrote:
> How can I access a Psycopg_database_connection within a python script.
> So far I have this which only returns a connection instance, but I want
> to pass the connection a query string.
> query1=context.Psycopg_database_connection('select * from studentdetails')
> return query1


that won't work as you need to set the query attribute of the DA - search 
the list history for an example as I can't remember off my head. This isn't 
really documented so you have to read to source of how ZSQL works if the DA 
doesn't make this explicitly possible. FWIW it is very easy to use the 
execute method of our mxODBCZopeDA for exactly this kind of situation. As 
I've said before you might better off writing a standalone script outside 
of Zope if you don't need any interaction with Zope or as an ExternalMethod 
if you do.

Good luck!

Charlie Clark

Professional Python Services directly from the Source
 >>> Python/Zope Consulting and Support ...        http://www.egenix.com/
 >>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
 >>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
2005-10-17: Released mxODBC.Zope.DA 1.0.9        http://zope.egenix.com/

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::

More information about the Zope-DB mailing list