事务SQLite3和Python中的更新

时间:2011-05-27 10:55:03

标签: python sqlite

我使用

更新用户表(sqlite3和Python)中的行
def update_user_by_id(self,id,first_name,last_name,username,password,privilege,email):
    '''Update user in table user based on id on passed parameters'''
    try:
        connection=sqlite3.connect(self.__path_users)
        cursor=connection.cursor()
        cursor.execute('''UPDATE user SET first_name=?,last_name=?,username=?,password=?,privilege=?,email=? where id=?''',first_name,last_name,username,password,privilege,email,id)
        connection.commit()
        connection.close()
        print "Affected: %d", cursor.rowcount
    except sqlite3.Error, e:
        print "Ooops:", e.args[0]

但如何将其纳入交易?

1 个答案:

答案 0 :(得分:1)

这已经是一个交易。当您致电connection.commit()时,交易将被提交。如果您想将其回滚,请删除该行。