为什么执行后我们需要connector.commit()?

问题描述:

我有一个运行查询命令的SQLite/Python代码,如下所示。为什么执行后我们需要connector.commit()?

def queryDB(self, command_):_ 
    self.cursor.execute(command_) 
    self.connector.commit() # <---- ??? 
    ... 

它工作得很好,但我有一些问题。

  • 为什么需要connector.commit()?它有什么作用?
  • cursor.execute()做什么?
+0

这些是SQL问题。不是Python或SQLite连接。阅读:http://en.wikipedia.org/wiki/Commit_(data_management) – 2010-09-11 00:31:56

+0

http://docs.python.org/library/sqlite3.html – 2010-09-11 07:28:40

每本网站:http://www.amk.ca/python/writing/DB-API.html

“支持事务的数据库,Python接口默默启动时,光标会创建一个事务的commit()方法提交更新使用游标进行的,而在这些数据库中,commit()什么也不做,但你仍然应该叫它以便与那些支持交易的数据库兼容。“