[Zope] Passing ZMySQL database connections to external methods. Possible ?

Hannu Krosing hannu@trust.ee
Sun, 29 Aug 1999 15:01:57 +0300


happyrhino@usa.net wrote:
> 
> It would be good if I could also benefit from the  persistent
> database connections. So, is it also possible to pass a Zope
> Database Connection object to an external method ?
> For example, I am using the ZMySQL database connection. It would be
> super to pass that to an external method and still use the identical
> syntax as the native Python MySQLmodule. (eg. ZMySQL.query(),
> ZMySQL.fetchrows() in place of DBH.query(), DBH.fetchrows().)
> In fact, that would be like gaining all the advantages of Zope but
> with little rewriting of code !  Is it possible ?

You can probably extract it from a ZMySQL adapter object (look at the 
source of ZMySQL and if the raw connection is hidden, add a method 
(like getRawConnection()), then after restarting zope, if you have a 
folder with a dbConnection called myZMySQLConnction you can access the 
raw connection from an external method in the same folder or below it
by using:

def useZMySQLConnection(self):
    DBH = self.myZMySQLConnction.getRawConnection()
    # here do all kinds of fancy things with it

> However, I don't think these results would be cached like ZQL methods,
> would they ?

No they won't

--------------
Hannu