Re: [Zope] Accessing ZSQL connection from external method
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') [another 20 min. later] I benchmarked it agains opening a connection and cursor and then execute() and fetchall(). Using the Zope connection took about 60% of the time the other method took. I wonder if there are any disadvantages??? --Ragnar
I'll look around, but preliminarily, it looks like it has a __call__ method that can be used to invoke it. Not sure on how you pass parameters to it. It returns a sequence that contains the records retrieved, then you can do with the sequence as you see fit. I'll look around some more and let you know what else I find.
On Mon, Mar 27, 2000 at 10:28:27PM +0200, Ragnar Beer wrote:
Aha! I have it!
Your external methods are given a pointer to self as the first arguement. You can use this to access any methods in the current folder (self is the current folder) So just call:
self.MyZSQLMethod(arg1, arg2)
where arg1 and arg2 are would be the arguments for the ZSQL Method.
Could you also find out how to do anything useful with it? I have no idea how to use it. Is there a cursor() method and so on?
-- The things that interest people most are usually none of their business.
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
participants (2)
-
Daryl Tester -
Ragnar Beer