Python DB API - commit() v. execute("commit transaction")?

Ian Kelly ian.g.kelly at gmail.com
Tue May 30 11:11:23 EDT 2017


On Tue, May 30, 2017 at 8:19 AM, Joseph L. Casale
<jcasale at activenetwerx.com> wrote:
> -----Original Message-----
> From: Python-list [mailto:python-list-
> bounces+jcasale=activenetwerx.com at python.org] On Behalf Of Ian Kelly
> Sent: Tuesday, May 30, 2017 8:12 AM
> To: Python <python-list at python.org>
> Subject: Re: Python DB API - commit() v. execute("commit transaction")?
>
>> There's no difference I'm aware of in the implementations I've used,
>> but having a consistent API does allow for constructions such as:
>>
>> try:
>>     do_stuff(conn)
>> except:
>>     conn.rollback()
>> finally:
>>     conn.commit()
>
> So you always commit even after an exception?

Doh, that finally should have been else. Though to be fair, committing
immediately after rolling back should be harmless if there are no
other threads using the same connection.



More information about the Python-list mailing list