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

Jon Ribbens jon+usenet at unequivocal.eu
Tue May 30 11:12:55 EDT 2017


On 2017-05-30, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Tue, 30 May 2017 13:42:14 -0000 (UTC), Jon Ribbens
><jon+usenet at unequivocal.eu> declaimed the following:
>>On 2017-05-30, Skip Montanaro <skip.montanaro at gmail.com> wrote:
>>> Assuming the underlying database supports transactions, is there any
>>> difference between calling the commit() method on the connection and
>>> calling the execute method on the cursor with the "commit transaction"
>>> statement? It seems a bit asymmetric to me to start a transaction with
>>>
>>>   cur.execute("begin transaction")
>>>
>>> but end it with
>>>
>>>   conn.commit()
>>
>>Yes, I found this most peculiar.
>
> https://stackoverflow.com/questions/2546926/why-connection-in-pythons-db-api-does-not-have-begin-operation
>
> may offer some reasoning...  (along with its linked discussion
> https://groups.google.com/forum/#!topic/comp.lang.python/gNC_O6zUdAA )

I can't make head nor tail of what they are trying to say there.
Mind you, it doesn't help that the DB-API concept of cursors seems
to bear almost no resemblance to the SQL concept of cursors.

> 	The main argument I have for not using
> 		cur.execute("begin transaction") 
> is that the DB-API module concept of being in/out of a transaction might
> get out of synchronization.

What would you suggest doing instead?



More information about the Python-list mailing list