CREATE OR ALTER trigger ttbtelegra_conf_b02i for tbtelegra_conf
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('TBEPI',NEW.ID, HISTORICO);
    END
END;


CREATE trigger ttbtelegra_conf_b01u for tbtelegra_conf
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

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

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

    IF (HISTORICO <> '') THEN
    BEGIN
        HISTORICO = ' REGISTRO ALTERADO: '||HISTORICO;
        EXECUTE PROCEDURE SPI_HISTORICO('TBEPI',NEW.ID, HISTORICO);
    END
END;


CREATE OR ALTER trigger ttbtelegra_conf_b01d for tbtelegra_conf
active before delete position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

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

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