tags:

views:

36

answers:

1

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?
+2  A: 

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."

luther07