How to create a trigger with sqlite3 in python

0

I am making a simple graphical interface of a DB in which a name, password, last name, address and comment are inserted. Then you have four buttons that allow you to create, read, update or delete that information entered from the database. The problem I have is that I tried to make a trigger so that when updating information from a user the old data is saved in a different table but I miss an error and I do not know how to solve it. I leave the code here:

def update():

conexion=sqlite3.connect("Usuarios")
cursor=conexion.cursor()

cursor.execute('''CREATE TABLE USUARIO_ACTUALIZADO 
    (ANTERIOR_ID INTEGER PRIMARY KEY AUTOINCREMENT, ANTERIOR_NOMBRE 
    VARCHAR(50), ANTERIOR_PASSWORD VARCHAR(50), 
    ANTERIOR_APELLIDO VARCHAR(50), ANTERIOR_DIRECCION VARCHAR(50), 
    ANTERIOR_COMENTARIOS VARCHAR(50), USUARIO VARCHAR(50))
    ''')

cursor.execute('''CREATE TRIGGER USUARIO_ACTUALIZADO_BU BEFORE UPDATE ON 
    DATOSUSUARIOS FOR EACH ROW 
    INSERT INTO USUARIO_ACTUALIZADO (ANTERIOR_NOMBRE, ANTERIOR_PASSWORD, 
    ANTERIOR_APELLIDO, ANTERIOR_DIRECION, ANTERIOR_COMENTARIO, USUARIO, 
    FECHA) 
    VALUES (OLD.NOMBRE, OLD.PASSWORD, OLD.APELLIDO, OLD.DIRECCION, 
    OLD.COMENTARIOS, CURRENT_USER())
    ''')

datos= miNombre.get(), miPassword.get(), miApellido.get(), 
miDireccion.get(),comentariosCuadro.get("1.0", END)

cursor.execute("UPDATE DATOSUSUARIOS SET NOMBRE=?, PASSWORD=?, APELLIDO=?, 
DIRECCION=?, COMENTARIOS=? WHERE ID= " + miId.get(), (datos))

conexion.commit()
messagebox.showinfo("BBDD", "Registro actualizado con éxito")

By the way I'm using sqlite3

    
asked by Diego Martinez 17.08.2018 в 12:34
source

0 answers