Why do we need connector.commit() after execution?
I have a SQLite/Python code that runs the query command as follows.
开发者_运维技巧def queryDB(self, command_):_
self.cursor.execute(command_)
self.connector.commit() # <---- ???
...
it works pretty well, but I have some questions.
- Why connector.commit() is needed? What does it do?
- What does cursor.execute() do?
Per this website: http://www.amk.ca/python/writing/DB-API.html
"For databases that support transactions, the Python interface silently starts a transaction when the cursor is created. The commit() method commits the updates made using that cursor, and the rollback() method discards them. Each method then starts a new transaction. Some databases don't have transactions, but simply apply all changes as they're executed. On these databases, commit() does nothing, but you should still call it in order to be compatible with those databases that do support transactions."
精彩评论