SET TERM ^ ;

CREATE OR ALTER trigger ttbmodelo_atributo_b02i for tbmodelo_atributo
active before insert position 1
AS
    DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

    IF ( NEW.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' REGISTRO INCLUIDO';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBMODELO_ATRIBUTO', NEW.ID, HISTORICO);
    END
END
^

SET TERM ; ^


SET TERM ^ ;

CREATE OR ALTER trigger ttbmodelo_atributo_b01u for tbmodelo_atributo
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(5000);
BEGIN
  HISTORICO = '';

  IF (OLD.ATRIBUTO_ID <> NEW.ATRIBUTO_ID) THEN
  BEGIN
    HISTORICO = HISTORICO || 'ATRIBUTO: ' || OLD.ATRIBUTO_ID || ' -> ' || NEW.ATRIBUTO_ID;
  END

  IF (HISTORICO <> '') THEN
  BEGIN
    HISTORICO = 'REGISTRO ALTERADO: ' || HISTORICO;

    EXECUTE PROCEDURE SPI_HISTORICO('TBMODELO_ATRIBUTO', OLD.ID, FN_ELIPSE(HISTORICO, 500));
    EXECUTE PROCEDURE SPI_HISTORICO('TBMODELO', OLD.MODELO_ID, FN_ELIPSE(HISTORICO, 500));
  END
END
^

SET TERM ; ^


SET TERM ^ ;

CREATE OR ALTER trigger ttbmodelo_atributo_b01d for tbmodelo_atributo
active before delete position 0
AS
   DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

    IF ( OLD.ID > 0) THEN
    BEGIN
        HISTORICO = HISTORICO||' REGISTRO EXCLUIDO';
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBMODELO_ATRIBUTO', OLD.ID, HISTORICO);
    END
END


^

SET TERM ; ^


