简体   繁体   中英

Update in transaction SQLite3 and Python

I update rows in user table (sqlite3 and Python) with

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]

but how to put this into transaction?

This is already a transaction. The transaction is commited when you call connection.commit() . If you would like to roll it back just remove that line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM