MySQL Connector/Python: How to use the start_transaction() method?

最后都变了- 提交于 2020-05-17 06:20:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!