问题
I am trying to access some records using MySQL Connector/Python but I am unable to understand how start_transaction()
is used.
I would be great if someone could shed some light on uses cases where it is required.
Update: After reading the docs carefully it looks like, the start_transaction()
method is only required when autocommit=True
. Is that true? I am still confused over this and documentation doesn't provide any examples.
回答1:
Yes, you normally use the connection.start_transaction() method to start a transaction when the autocommit feature is enabled.
Since MySQL Connector/Python is Python DB API-compliant, autocommit is disabled by default and the first SQL statement will implicitly begin a transaction. You must call connection.commit to commit the transaction.
来源:https://stackoverflow.com/questions/52723251/mysql-connector-python-how-to-use-the-start-transaction-method