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

Charlie Clark charlie at egenix.com
Tue Jul 27 05:23:34 EDT 2004


On 2004-07-26 at 04:57:15 [+0200], Dave Cinege 
<dcinege-mlists-dated-1091242644.04cdcc at psychosis.com> wrote:
> I'm working on my first project in Zope. The application is more dependant 
> on
> logic then presentation, so I'm pretty well settled that coding the majority
> of it in python external methods will work the best for for me.
> 
> 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.
> 
> What is the 'correct' thing to do with this DB connection? Should I have my
> external sql class be accessing a ZDatabase Connection object? Or should I
> still open my own connection, and if so how do I do this properly with
> persistance? (Examples please as I'm still pretty weak on the Zope API...)

The best thing is to use connection objects and ZSQL methods unless you have 
a need for extremely dynamic queries in which case you can use an external 
method to call the DA directly. Our mxODBCZopeDA has both query and execute 
methods for example which allow you to hook into Zope's transactional 
management but write your queries completely independently.

Charlie
-- 
Charlie Clark
eGenix.com

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/
________________________________________________________________________

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


More information about the Zope-DB mailing list