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
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor