[Tutor] sqlite3 COMMIT directive

Alan Gauld alan.gauld at btinternet.com
Tue Oct 1 12:28:14 CEST 2013


On 01/10/13 09:25, Tim Golden wrote:
> On 01/10/2013 09:03, Alan Gauld wrote:
>> You don't normally need to use COMMIT when programming SQLite from
>> 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.

Hmm, I didn't express that as I should but I was meaning within
a 'with' block (which the OP was using) based on this comment
in the docs:

"""
Connection objects can be used as context managers that automatically 
commit or rollback transactions. In the event of an exception, the 
transaction is rolled back; otherwise, the transaction is committed:
"""

Now I admit I didn't test it but I read that to imply that the with 
would autocommit. Am I mistaken?

-- 
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