[Tutor] sqlite3 COMMIT directive

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Oct 2 16:51:53 CEST 2013


On 01/10/2013 12:05, Alan Gauld wrote:
> 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.
>

I haven't followed this too closely as my SQL skills (like many others) 
are sadly out of date, but is it worth the hassle of raising an issue on 
the bug tracker to get the relevant docs changed, or is "slightly 
misleading" actually close enough?

-- 
Roses are red,
Violets are blue,
Most poems rhyme,
But this one doesn't.

Mark Lawrence



More information about the Tutor mailing list