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 ; ^

