[Zope] Accessing ZSQL connection from external method
Ragnar Beer
rbeer@uni-goettingen.de
Tue, 28 Mar 2000 13:23:55 +0200
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.