On 07/07/2013 06:43 AM, Chris Angelico wrote:
On Sun, Jul 7, 2013 at 11:13 PM, Wayne Werner <wa...@waynewerner.com> wrote:
Which you would then use like:


conn = create_conn()
with new_transaction(conn) as tran:
      rows_affected = do_query_stuff(tran)
      if rows_affected == 42:
           tran.commit()

Yep. There's a problem, though, when you bring in subtransactions. The
logic wants to be like this:

Is there some reason you can't simply do this?

 with new_transaction(conn) as tran1:
      tran1.query("blah")
      with tran1.subtransaction() as tran2:
          tran2.query("blah")
          with tran2.subtransaction() as tran3:
              tran3.query("blah")
              # roll this subtransaction back
          tran2.query("blah")
          tran2.commit()
      tran1.query("blah")
      tran1.commit()

--
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to