0

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

Ergest Basha
5,3693 gold badges8 silver badges22 bronze badges
asked Jan 18, 2024 at 11:17
2
  • Please add table definition , some data example and expected result, so we can understand what are you trying to achieve. See Tips for asking a good Structured Query Language (SQL) question Commented Jan 18, 2024 at 11:39
  • ... NEW.fecha_adquisicion||); - remove last || Commented Jan 18, 2024 at 13:39

1 Answer 1

0

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.

answered Feb 1, 2024 at 4:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.