CREATE OR ALTER trigger ttbpower_bi_painel_b01u for tbpower_bi_painel
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

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

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

    IF ( NEW.MENU_GRUPO IS DISTINCT FROM OLD.MENU_GRUPO) THEN
    BEGIN
        HISTORICO = HISTORICO||' MENU GP:'||COALESCE(OLD.MENU_GRUPO, '')||'->'||COALESCE(NEW.MENU_GRUPO, '');
    END

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

