[Tutor] sqlite3 COMMIT directive

Alan Gauld alan.gauld at btinternet.com
Tue Oct 1 13:05:20 CEST 2013


On 01/10/13 11:41, Tim Golden wrote:

>>>> Python, the database starts and ends transactions automatically from
>>>> within the execute() function.
>>>
>>> Not so, I'm afraid. If you want autocommit, you need to send an
>>> isolation_level of None to the .connect function.

>> """
>> Connection objects can be used as context managers that automatically
>> commit or rollback transactions.
>
> You're sort-of correct. What happens is that the database doesn't enter
> autocommit mode (you'll still need to specify the right isolation level
> on the .connect for that). Rather, the __exit__ method of the
> connection-as-context-manager issues the db.commit() call which will
> commit anything outstanding.

OK, That makes sense it's a bit like the file close at the end of a with 
block. So the docs statement that it automatically commits 
*transactions* is slightly misleading as it only commits the full 
content of the block which could hold multiple transactions.

Thanks for the clarification Tim.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list