Passing ZMySQL database connections to external methods. Possible ?
Before looking at Zope, I had already invested a lot of time in CGI scripts and so I've converted them all to external methods (replacing print's with StringIO objects and returning StringIO.getvalue()). But the only benefit of using Zope then seems to be that I'll have PCGI instead of CGI. 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 ? However, I don't think these results would be cached like ZQL methods, would they ? Even so, it would still be a quick start until I have time to rewrite all of my scripts as ZSQL methods. Sorry for all of the questions. There's a lot to learn. TIA, Henry ____________________________________________________________________ Get free email and a permanent address at http://www.netaddress.com/?N=1
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
participants (2)
-
Hannu Krosing -
happyrhinoï¼ usa.net