Is there a better way to handle multiple connections of a single table
than this:
> class mytable(SQLObject):
> _connection = localConnection
> name = StrCol(length=255)
> data = StrCol()
>
> localdata = mytable.select()
> # change connection
> mytable._connection = remoteConnection
> remotedata = mytable.select()
> # change it back...
> mytable._connection = localConnection
The object returned by the two different connections are actually
different objects and update properly through the right database
connection, but any related objects returned through a RelatedJoin are
the same, using the current connection. Is there a better way to do
this?
I thought I might be able to do this:
> class mytableRemote(mytable):
> _connection = remoteConnection
...but it doesn't seem to work. Or, I thought I could just sub-class
SQLObject...
> class mySQLObject(SQLObject):
> _connection = localConnection
> def connectRemotely(self):
> self.__class__._connection = remoteConnection
> def connectLocally(self):
> self.__class__._connection = localConnection
I know that I can duplicate my table definition modules and just give
each one a different connection object, but I want to be able to re-use
the class definitions...
Thanks,
Tracy
|