
CREATE TRIGGER TTBCOMPOSICAO_B01I FOR TBCOMPOSICAO
ACTIVE BEFORE INSERT POSITION 9
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';
    IF(NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' Composição Incluída!';
    END
    
    IF(HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBCOMPOSICAO',NEW.ID,HISTORICO);
    END
END;

CREATE TRIGGER TTBCOMPOSICAO_B01U FOR TBCOMPOSICAO
ACTIVE BEFORE UPDATE POSITION 9
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';
    IF(NEW.DESCRICAO <> OLD.DESCRICAO) THEN
    BEGIN
         HISTORICO = HISTORICO||' Descrição: '||OLD.DESCRICAO||' -> '||NEW.DESCRICAO;
    END
    
    IF(HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBCOMPOSICAO',NEW.ID,HISTORICO);
    END
END;

CREATE TRIGGER TTBCOMPOSICAO_B02D FOR TBCOMPOSICAO
ACTIVE BEFORE DELETE POSITION 9
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';
    IF(OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' Composição Excluída!';
    END
    
    IF(HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBCOMPOSICAO', OLD.ID, HISTORICO);
    END
END;



                                                                                                                 