[SQLObject] How to synchronize and close transactions
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Evandro V. M. <ev...@as...> - 2005-08-03 16:38:41
|
I couldn't find any method in SQLObject to syncronize transactions. Let's supose I have multiple users using an aplication and, of couse, with multiple connections. First I create a local transaction which I don't want to use for inserts, updates or deletes, only for selects. t1 = __connection__.transaction() After some time, when other users has changed the database, I need to synchronize it. For this job I've created the method bellow: def sync(trans): trans.rollback() trans.begin() Where trans is a Transaction object. I used rollback to ensure that I'm not commiting anything wrong since the transaction sent should not have changed any data. I have tested this code and it works pretty well but... Is this approach right ? Is there a better idea ? Now, talking about DBMS connections, I can see using SQLObject that for a n number of transactions opened I have a n number of DBMS connections. I think this is a common behavior for relational databases, is not it ? Ok, since my application uses multiple transactions and create them everywere I need to close them properly after call commit or rollback, otherwise problems with maximum number of connections will appear. I saw in SQLObject a small thread with this subject and thinks end up whith the sense that there is no way to close a DBMS connection. See: http://permalink.gmane.org/gmane.comp.python.sqlobject/1761 BTW I found a solution for this problem(or think I found): def close_transaction(trans=None): trans._connection.close() Again, where trans is a transaction object. Any suggestions ? -- Evandro Vale Miquelito : ev...@as... Async Open Source - Brazil | http://www.async.com.br |