[Zope] Accessing ZSQL connection from external method

Daryl Tester dt@picknowl.com.au
Tue, 28 Mar 2000 21:26:59 +0930


Ragnar Beer wrote:

> I just found a HOWTO by jpenny: Accessing a ZSQL method from an
> external method. It helps a bit but actually I don't want to use a
> ZSQL method I just want to take advantage of a persistant connection.
> Wait, I got an idea ...
> 
> [20 min. later]
> Hooray! Try this: I have an open ZMySQL Database called
> 'my_connection'. Now I can query the db from my external method with:
> 
> self.my_connection._v_database_connection.query('select * from whatever')

Synchronicity!  I've just read the same document today and found the python
code for database connections (in ./lib/python/Shared/DC/ZRDB/Connection.py,
if anyone is interested :-), and am about to try passing my own queries in.

> I wonder if there are any disadvantages???

The only one I could immediately think of was "what if the database
connection hasn't been opened".  I can see the method for
manage_open_connection() (and _v_connected/connected() for the status
of the connection), but don't feel 100% comfortable calling Zope
internals just yet.  Any caveats for just semi-blindly calling
.manage_open_connection() if .connected() returns false?


Regards,
  Daryl Tester