2010-09-10 21 views
-1

我有一個運行查詢命令的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

回答

2

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

「支持事務的數據庫,Python接口默默啓動時,光標會創建一個事務的commit()方法提交更新使用遊標進行的,而在這些數據庫中,commit()什麼也不做,但你仍然應該叫它以便與那些支持交易的數據庫兼容。「