Almira Bojani
Almira Bojani

Reputation: 579

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 ?

Upvotes: 0

Views: 1225

Answers (1)

garnertb
garnertb

Reputation: 9594

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.

Upvotes: 1

Related Questions