Hi List,
I would like some advice on attempting the following.
I want to use multiple database connections (to multiple databases) with
the same SQLObject definitions. For example, with MySQL I setup three
databases: A, B and C and define the same set of SQLObjects in each, say:
class MyTable1 (SQLObject):
dbField1 = IntCol()
dbField2 = StringCol()
class MyTable2 (SQLObject) :
dbField3 = DateCol()
dbField4 = StringCol()
Normally what would I do is place these lines in the same file as the
definitions of the tables above:
connection = connectionForURI('mysql://blah:[EMAIL PROTECTED]:3306/blah')
sqlhub.processConnection = connection
And I gather this effectively means that the SQLObjects all use the same
connection. The alternatives seems to be (a) set the _connection
property of each instance, or (b) pass the connection object in at
instance creation time (as detailed in the documentation).
So to do what I want to do would would mean I probably need to create
three connection instances, connA, connB and connC and pass these as an
argument when I access the SQLObjects. For example:
connA = connectionForURI('mysql://blahA:[EMAIL PROTECTED]:3306/blahA')
connB = connectionForURI('mysql://blahB:[EMAIL PROTECTED]:3306/blahB')
connC = connectionForURI('mysql://blahC:[EMAIL PROTECTED]:3306/blahC')
tA = MyTable1.get(1, connA)
tB = MyTable1.get(1, connB)
tC = MyTable1.get(1, connC)
Can anyone confirm this as the best way to achieve multiple connections?
cheers, Alex.
--
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss