[Zope-DB] using connection from script

Federico Di Gregorio fog@mixadlive.com
02 Oct 2001 17:19:32 +0200


On Tue, 2001-10-02 at 13:27, Jochen Mader wrote:
> Hello,
> I'm a newbie with zope,  switched to zope 3 days ago after programming wih 
> j2ee for 2 years (may that darn thing burn in hell). After recreating some of 
> my projects within zope (it took me weeks to utilize ejbs to do that, in zope 
> it worked in just some hours *sigh*). 
> My problem now is that I don't know wether it is possible to do the following:
> I have defined a Postgres connection using psycopg. I know that it's 
> possible to get a connection by doing 
> context.<connectionname>.connect(<credentials>)
> but that is not what I want to do. I'd like to just use the defined 
> connection (it has already been opened with the right credentials so why 
> should I open a new connection and giving the credentials again).

other people already explained why is better to use zsql methods. if you
really need to use your own connection, the connect(<credentials>)
method is the right one. while psycopg is thread safe at level 2, zope
does not use this feature (i will be happy to put that in zpsycopgda if
someone can point me to some _good_ documentation about zope DAs).
opening one more connection is not that bad, you also gain the following
benefits:

1/ a separate transaction (mmm... maybe you don't want that, but work in
zope transaction, i admit i don't know how to do that); and

2/ when your script exits the connection is automagically closed and
recycled (but remember to commit() before leaving the python method.)

ciao,
federico

-- 
Federico Di Gregorio
Debian GNU/Linux Developer & Italian Press Contact        fog@debian.org
INIT.D Developer                                           fog@initd.org
                             Best friends are often failed lovers. -- Me