SV: [Zope] Using MySQL from a product

Carsten Gehling carsten@gehling.dk
Wed, 30 Jul 2003 13:37:19 +0200


Thank you Gilles and Fritz. Funny... Just an hour before getting your
suggestions, I thought "Why don't I just call the MySQLdb directly? I do
that in other python scripts. And lo and behold! It worked :-)

I actually did your suggestion number one Gilles, with connecting to the
database from inside the method. I am very interested in the connection p=
ool
idea - I'll probably build it into my product when time comes.

- Carsten


> -----Oprindelig meddelelse-----
> Fra: zope-admin@zope.org [mailto:zope-admin@zope.org]P=E5 vegne af Gill=
es
> Lenfant
> Sendt: 29. juli 2003 23:31
> Til: Nick Arnett; Zope@Zope.Org
> Emne: Re: [Zope] Using MySQL from a product
>
>
> ----- Original Message -----
> From: "Nick Arnett" <narnett@mccmedia.com>
> To: "Zope@Zope.Org" <zope@zope.org>
> Sent: Tuesday, July 29, 2003 7:18 PM
> Subject: RE: [Zope] Using MySQL from a product
>
>
> > > -----Original Message-----
> > > From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of
> > > Gilles Lenfant
> >
> > ...
> >
> > > Warning, you should get the MySQLdb.Connection objects from a pool =
of
> > > connections : a MySQLdb.Connection object is not thread safe.
> >
> > Could you explain what this implies, in a practical sense?
> Would it mean
> > having a shared module that creates connections, then all
> external methods
> > would import it?  How about products that use MySQLdb?
> >
> > Nick
> >
>
> You can do 2 things :
>
> 1/ simple : in your product methods, create a new Connection
> object for each
> method that needs to access MySQL
>
> class Foo(...):
> __ def foo(self):
> ____db =3D MySQLdb.Connnect(...)
> ____dbc =3D db.cursor()
> ____...
> ____db.execute(someSqlQuery)
> ____...
> ____db.close()
> ____return xxx
>
> 2/ complex but with better performances (creating a new connection may
> require some time):
> Create a pool of connections. Those connections are created at
> Zope startup,
> and dynamically distributed to (and locked for) the various methods tha=
t
> need to make SQL queries. If there's not enough available connections a=
t a
> give time, a new one is created and included in the pool for future use=
.
> Using such constructs make faster products (for methods that make SQL
> queries).
>
> I'll join a sample of connection pool I used some times ago.
>
> --Gilles
>
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )
>