[英]Update in transaction SQLite3 and Python
我使用更新用户表(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]
但是如何将其放入交易中?
这已经是一笔交易了。 当您调用connection.commit()
时,事务被提交。 如果您想回滚它,只需删除该行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.