Using an arbitrary connection on a ZSQL Method
Just did a useful hack I wanted share... Occasionally I find it useful to have one SQL Method that I can call with a different DB connection, programatically. For example I have a test and a live database. Using manage_editProperties each time of course means writing a new copy of the object. The following patch means that you can override the connection_id on the ZSQLMethod with CONNECTION_ID in REQUEST. This could be cleaned up a little of course but I found it useful in conjunction with session management. --- l:\lib\python\Shared\DC\ZRDB\DA.py Thu May 10 16:29:25 2001 +++ q:\lib\python\Shared\DC\ZRDB\DA.py Thu May 10 15:08:36 2001 @@ -457,11 +457,14 @@ if hasattr(self, 'REQUEST'): REQUEST=self.REQUEST else: REQUEST={} - try: dbc=getattr(self, self.connection_id) + if REQUEST is not None and REQUEST.has_key('CONNECTION_ID'): c_id = REQ UEST['CONNECTION_ID'] + else: c_id = self.connection_id + + try: dbc=getattr(self, c_id) except AttributeError: raise AttributeError, ( "The database connection <em>%s</em> cannot be found." % ( - self.connection_id)) + c_id)) try: DB__=dbc() except: raise 'Database Error', ( Cheers. -- Andy McKay.
participants (1)
-
Andy McKay