Monday, 29. August 2005 13:48.
New method Query.fetchall() which does a fetchall() on the query's DataIterator. This is used in ledger's DemoPopulator to avoid the database table is locked problem.The following code raises an OperationalError because a table cannot be updated while we are looping on it:
q=sess.query(Partner) for p in q: p.lock() p.currency=BEF p.unlock()
The following code works because the fetchall() does the loop before, collecting the rows into a list. When we iterate on this list, the table has already been released.
q=sess.query(Partner) for p in q.fetchall(): p.lock() p.currency=BEF p.unlock()
Of course this approach works only with reasonable number of rows to be updated. It is a non-trivial problem.