Il 13/10/2021 15:46 Daniele Varrazzo ha scritto:
On Wed, 13 Oct 2021 at 15:21, Paolo De Stefani <pa...@paolodestefani.it> wrote:

I was used to wrote a "with con.cursor() as cur:" that now i hato to
replace with:

with con.transaction():
     with con.cursor() as cur:
         cur.execute("ANY SQL STATEMENT")

and everything works as expected (or i expect...)

You can even write:

    with con.transaction():
        con.execute("ANY SQL STATEMENT")

But is it even useful to wrap a transaction around any single
statement? I still think you'd be better off with an autocommit
connection.

In my small application i use only one connection (per client). I manage the customer orders of a food stand. The orders have header and lines. In that case i do a commit only after insert/update of the 2 table's records so i can not use an autocommit connection.

But what i wrote before and your suggestion are just fine for my needs, thanks


--
Paolo De Stefani


Reply via email to