[Zope] ZSQMethods shipped with a Product

Peter Sabaini peter at sabaini.at
Wed Nov 26 17:41:52 EST 2003


Gilles Lenfant wrote:
> Hi,
> 
> Is there a way to do FS based ZSQL methods in a Product ?
> Actually, my product (under development) uses direct MySQLdb.connections 
> created/deleted for each method. This works but...
> 
> 1/ It's not easy to be DBMS engine independant that way.
> 
> 2/ Creating new DB connector for each Web transaction slows down the stuff.

Why dont you use a regular database adaptor from within your Product?

Given a eg. MySQL database adapter named 'the_mysql_da', I'd use 
something like this:

import Acquisition
from Products.ZSQLMethods.SQL import SQL

# this class finds the DA via acquisition
class MyZSQLMethods(Acquisition.Implicit):
     aZSQLMethod = SQL('aZSQLMethod', 'the title', 'the_mysql_DA',
                       'zsql_param1 zsql_param2',
                       'select xyz from my_relation ... ')

class MyProduct(...):
      sql = MyZSQLMethods()
      def someMethod(self):
           rs = self.sql.aZSQLMethod(
                     zsql_param1='foo', zsql_param2='bar')


Take a look into lib/python/Products/ZSQLMethods/SQL.py and 
lib/python/Shared/DC/ZRDB/DA.py to find out more about the SQL class

  - peter.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3216 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.zope.org/pipermail/zope/attachments/20031126/44a8de8f/smime.bin


More information about the Zope mailing list