I'm trying to rewrite a Trigger that I made with Firebird to a MySql Trigger.
I realy have no idea what could be. If anyone could help me... thanks
I'm submiting the SQL with PHP just like follows, and the error message is:
Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$ CREATE TRIGGER FP_PAGO_AI AFTER INSERT ON FORMA_PGTO FOR EACH R' at line 1
The trigger's code is:
$str[] = "
DELIMITER $$
CREATE TRIGGER FP_PAGO_AU AFTER UPDATE ON FORMA_PGTO
FOR EACH ROW
BEGIN
declare rec_count integer;
declare pg_count integer;
declare cp_pago integer;
select count(*) from forma_pgto fp where fp.id_cpagar=new.id_cpagar into rec_count;
select count(pago) from forma_pgto f where f.id_cpagar=new.id_cpagar and f.pago=1 into pg_count;
/* Se todas parcelas estao pagas, entao setar conta paga */
if (rec_count = pg_count) then
update cpagar c set c.pago=1 where c.id=new.id_cpagar;
/* Senao */
else
/* Se CPAGAR.PAGO = 1, recebe 0 */
select cpg.pago from cpagar cpg where cpg.id=new.id_cpagar into cp_pago;
if (cp_pago = 1) then /* Se cp_pago = 1 */
update cpagar set pago=0 where id=new.id_cpagar;
end if;
end if;
END
END $$
DELIMITER ;
";