Why connection in Python's DB-API does not have "begin" operation?
Posted
by newtover
on Stack Overflow
See other posts from Stack Overflow
or by newtover
Published on 2010-03-30T16:38:54Z
Indexed on
2010/03/30
17:43 UTC
Read the original article
Hit count: 309
Working with cursors in mysql-python I used to call "BEGIN;", "COMMIT;", and "ROLLBACK;" explicitly as follows:
try:
cursor.execute("BEGIN;")
# some statements
cursor.execute("COMMIT;")
except:
cursor.execute("ROLLBACK;")
then, I found out that the underlying connection object has the corresponding methods:
try:
cursor.connection.begin()
# some statements
cursor.connection.commit()
except:
cursor.connection.rollback()
Inspecting the DB-API PEP I found out that it does not mention the begin() method for the connection object, even for the extensions.
Mysql-python, by the way, throws the Deprecation Warning, when you use the method. sqlite3.connection, for example, does not have the methd at all.
And the question is why there is no such method in the PEP? Is the statement somehow optional, is it enough to invoke commit() instead?
© Stack Overflow or respective owner