INSERT INTO TBMENU (DESCRICAO, CONTROLE, GRUPO, SUBGRUPO, TIPO, URL)
            VALUES ('CADASTRO DE QUALIFICAÇÃO DE SÓCIOS', 17020, 'CONT', 'CONT', '1   ', '');

ALTER TABLE TBQUALSOCIO
    ADD STATUS INTEGER;

update TBQUALSOCIO set status = 1;

CREATE trigger ttbqualsocio_b01i for tbqualsocio
active before insert position 0
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('TBQUALSOCIO',NEW.id, HISTORICO);
    END
end;

CREATE trigger ttbqualsocio_b01u for tbqualsocio
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

    HISTORICO = '';

    IF ( OLD.descricao <> NEW.descricao) THEN
    BEGIN
        HISTORICO = HISTORICO||'Descricao:'|| OLD.descricao||'->'||NEW.descricao;
    END
	
	IF ( OLD.status <> NEW.status) THEN
    BEGIN
        HISTORICO = HISTORICO||', Status:'|| OLD.status||'->'||NEW.status;
    END

    IF (HISTORICO <> '') THEN
    BEGIN
        EXECUTE PROCEDURE SPI_HISTORICO('TBQUALSOCIO',NEW.id, HISTORICO);
    END
end;

CREATE OR ALTER trigger ttbqualsocio_b01d for tbqualsocio
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('TBQUALSOCIO',old.id, HISTORICO);
    END
end;


