CREATE OR ALTER TRIGGER TTBLOCALIZACAO_FAMILIA_B02I FOR TBLOCALIZACAO_FAMILIA
ACTIVE BEFORE INSERT POSITION 9
AS
declare variable HISTORICO VARCHAR(500);
BEGIN
   HISTORICO = '';
   IF(NEW.FAMILIA_ID IS NOT NULL)then
   BEGIN
       HISTORICO = HISTORICO||'Fam.'||new.familia_id||' Incluida';
   END

   IF(HISTORICO <> '') THEN
   BEGIN
      EXECUTE PROCEDURE SPI_HISTORICO('TBLOCALIZACAO',NEW.LOCALIZACAO_ID,HISTORICO);
   END
END;

CREATE TRIGGER TTBLOCALIZACAO_FAMILIA_B01D FOR TBLOCALIZACAO_FAMILIA
ACTIVE BEFORE DELETE POSITION 9
AS
declare variable HISTORICO VARCHAR(500);
BEGIN
   HISTORICO = '';
   IF(OLD.FAMILIA_ID IS NOT NULL)then
   BEGIN
       HISTORICO = HISTORICO||'Fam.'||OLD.familia_id||' Excluida';
   END

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