Accessing Zope DA connection from external method
Jpenny wrote a little how-to about accessing ZSQL Method from External Method. This has really whetted my appetite. At the moment, my external methods create and destroy their connections to the database whenever they are called. This can potentially be expensive when scaling up. Can anyone point out how do I reference a Zope DA Connection from an external method. This way I can make use of an existing open connection instead. Thanks in advance Chui
Chui Tey wrote:
Jpenny wrote a little how-to about accessing ZSQL Method from External Method. This has really whetted my appetite.
At the moment, my external methods create and destroy their connections to the database whenever they are called. This can potentially be expensive when scaling up.
Can anyone point out how do I reference a Zope DA Connection from an external method. This way I can make use of an existing open connection instead.
From a short look at the source it seems that you can just use
YourZopeConnection.query('select * from data') I quess the result will be the same as from using ZSQL Method, but it may be something simpler. If you find something out, please let us know too ;) ------------- Hannu
On Mon, 27 Sep 1999, Hannu Krosing wrote:
Can anyone point out how do I reference a Zope DA Connection from an external method. This way I can make use of an existing open connection instead.
From a short look at the source it seems that you can just use
YourZopeConnection.query('select * from data')
I quess the result will be the same as from using ZSQL Method, but it may be something simpler.
Does anyone know if we can retrieve a pyDB 1.0 compliant Connection object from a Zope DA? My guess is probably not, as I don't think a Zope DA has to be implemented on top of this interface. I need to perform the same query a few thousand times, and would like to avoid the SQL compilation step by reusing the same cursor and just rebinding the parameters. Does anyone know if ZSQL methods perform this optimization behind our backs, or if it would be possible for a particular Zope DA to do this optimization? I'd guess it would be up to an individual DA to do this optimization, as pyDB 1.0 didn't specify how parameter binding would work and pyDB 2.0 for some ridiculous reason lets it be done in 4 different ways. ___ // Zen (alias Stuart Bishop) Work: zen@cs.rmit.edu.au // E N Senior Systems Alchemist Play: zen@shangri-la.dropbear.id.au //__ Computer Science, RMIT WWW: http://www.cs.rmit.edu.au/~zen
OK this worked: def external_query(self): sql = """ SELECT CreatedBy, AssignTo, DateCreated FROM tblJOB WHERE CreatedBy LIKE '%phil%' """ return self.connODBCJob().query(sql) but this didn't # in Extensions/testconn.py def external_query(self): return self.connODBCJob.query('SELECT * FROM tblJOB') and this hangs Zope (I think) # in Extensions/testconn.py def external_query(self): c = self.connODBCJob() return c.query('SELECT * FROM tblJOB') Only caveat is that the <dtml-in> tag doesn't seem to work with this external method. Hannu Krosing wrote:
Chui Tey wrote:
(snip)
Can anyone point out how do I reference a Zope DA Connection from an external method. This way I can make use of an existing open connection instead.
From a short look at the source it seems that you can just use
YourZopeConnection.query('select * from data')
I quess the result will be the same as from using ZSQL Method, but it may be something simpler.
If you find something out, please let us know too ;)
------------- Hannu
participants (3)
-
Chui.Tey@env.qld.gov.au -
Hannu Krosing -
Stuart 'Zen' Bishop