how u doing?,
I have a problem that I don't understand, when I create a Trigger in Mysqlite, check it:
c.execute("""CREATE TRIGGER ahoraSI BEFORE INSERT ON Productos
FOR EACH ROW
BEGIN
INSERT INTO Registro_cambios VALUES (' Numero de pedido ' ||NEW.id|| ' Nombre de producto ' ||NEW.nombre_producto|| ' fecha de adquisicion: ' ||NEW.fecha_adquisicion|| ' cliente asociado ' ||NEW.fecha_adquisicion||);
END """)
The thing is that when I add a simple string like "new product" to "Registro_cambios " it works but when I try to do it like this with the actual informacion of the products using ||NEW."something"|| doesn't work and always Bash return me that is a syntaxis problem:
"sqlite3.OperationalError: near ")": syntax error" if someone can help me, Thanks
1 Answer 1
It is always good to split long queries to multi-line:
c.execute("""CREATE TRIGGER ahoraSI BEFORE INSERT ON Productos
FOR EACH ROW
BEGIN
INSERT INTO Registro_cambios
VALUES (' Numero de pedido ' ||
NEW.id||
' Nombre de producto ' ||
NEW.nombre_producto||
' fecha de adquisicion: ' ||
NEW.fecha_adquisicion||
' cliente asociado ' ||
NEW.fecha_adquisicion||
);
END """)
This way, you immediately see that after adding field NEW.fecha_adquisicion
you are trying to add something else. But instead there is just an unexpected )
. So you have an error.
... NEW.fecha_adquisicion||);
- remove last||