|
Hi, Web.py does not do row locking as far as we can tell. We have found that a tiny patch to web.select is desirable in order to do row locking. Row locking solves the read-modify-write problem, where another thread can read your row at the same time as you, and whoever commits last wins rather than having the transactions done in sequence. This is especially critical with financial transactions. The solution is to allow the words "FOR UPDATE" to be appended to the sql for a select statement. The lock is automatically released at the end of the transaction. Use it by adding the keyword argument to select(for_update=True). This works fine for postgresql (pg row locking docs). I haven't tried it on other databases. The patch is just three lines of db.py as below: @@ -506,7 +506,7 @@ ]), dictionary.values()) def select(tables, vars=None, what='*', where=None, order=None, group=None, - limit=None, offset=None, _test=False): + limit=None, offset=None, for_update=False, _test=False): """ Selects `what` from `tables` with clauses `where`, `order`, `group`, `limit`, and `offset`. Uses vars to interpolate. @@ -572,6 +572,9 @@ for (sql, val) in sql_clauses: qout += gen_clause(sql, val) + if for_update: + qout += ' FOR UPDATE' + if _test: return qout return query(qout, processed=True) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web.py" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/webpy?hl=en -~----------~----~----~----~------~----~------~--~--- |
