[Zope-DB] Proper way to do DB connections from external methods?

Dieter Maurer dieter at handshake.de
Mon Jul 26 15:40:54 EDT 2004


Dave Cinege wrote at 2004-7-25 22:57 -0400:
> ...
>Right now I am just directly opening (and not closing...yes bad) a MySQL 
>connection with each call to an external method. I've no interest in using 
>zsql methods, as I am very happy using my own sql wrapper class, and do not 
>want to change. 

Then you will have to learn a lot -- about integration
with Zope's transaction and publishing framework.

As you are using MySQL, you might not be interested in transactions.
This would facilitate things wastly...
Otherwise, you must register a TM (Transaction Manager)
with Zope's transaction ("get_transaction().register(TM)").
The transaction informs the TM about abort/commit by calling
appropriate methods on the TM.

>What is the 'correct' thing to do with this DB connection?

You do not do it this way but use Z SQL Methods or
at least the "query" method of DA's.

>Should I have my 
>external sql class be accessing a ZDatabase Connection object?

This may correspond to the above mentioned "query" method..

>Or should I 
>still open my own connection,

You will need to manage such connections...

>and if so how do I do this properly with 
>persistance?

Look at how DA's do it...

(Examples please as I'm still pretty weak on the Zope API...)

Go for the easy way (Z SQL Methods).
Do not expect that you get much help for the hard way
(when you want to go the hard way, you must be getting
strong. As the name suggests, it will get hard).

-- 
Dieter


More information about the Zope-DB mailing list