SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_b03i for tbcurriculo
active before insert position 2
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('TBCURRICULO',NEW.ID, HISTORICO);
    END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_b02u for tbcurriculo
active before update position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN
    HISTORICO = '';

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

    IF ( NEW.DATA_NASCIMENTO <> OLD.DATA_NASCIMENTO) THEN
    BEGIN
        HISTORICO = HISTORICO||' DT.NASC:'||OLD.DATA_NASCIMENTO||'->'||NEW.DATA_NASCIMENTO;
    END

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

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

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

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

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

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

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

    IF ( NEW.FONE_1 <> OLD.FONE_1) THEN
    BEGIN
        HISTORICO = HISTORICO||' FONE 1:'||OLD.FONE_1||'->'||NEW.FONE_1;
    END

    IF ( NEW.FONE_2 <> OLD.FONE_2) THEN
    BEGIN
        HISTORICO = HISTORICO||' FONE 2:'||OLD.FONE_2||'->'||NEW.FONE_2;
    END

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

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

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


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

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_b01d for tbcurriculo
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('TBCURRICULO',OLD.ID, HISTORICO);
    END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_b01u for tbcurriculo
active before update position 1
AS
BEGIN
   IF(NEW.DATA_ATUALIZACAO IS NULL) THEN
       NEW.DATA_ATUALIZACAO = CURRENT_DATE;
END
^

SET TERM ; ^



----------------------------------------------------- FORMACAO --------------------------------------------------------------------

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_formacao_b02i for tbcurriculo_formacao
active before insert position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = ' FORMACAO INCLUIDA: '||NEW.id;

   IF (HISTORICO <> '') THEN
       BEGIN

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', NEW.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_formacao_b01u for tbcurriculo_formacao
active before update position 0
AS
BEGIN
   IF(NEW.DATA_ATUALIZACAO IS NULL) THEN
       NEW.DATA_ATUALIZACAO = CURRENT_DATE;
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_formacao_b02u for tbcurriculo_formacao
active before update position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = '';

   IF (OLD.TIPO_CURSO <> NEW.TIPO_CURSO) THEN
       BEGIN
       HISTORICO = HISTORICO||' TP.CURSO'||OLD.TIPO_CURSO||'->'||NEW.TIPO_CURSO;
       END

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

   IF (OLD.INSTITUICAO <> NEW.INSTITUICAO) THEN
       BEGIN
       HISTORICO = HISTORICO||' INSTITUICAO:'||OLD.INSTITUICAO||'->'||NEW.INSTITUICAO;
       END
   
   IF (OLD.DATA_INICIAL <> NEW.DATA_INICIAL) THEN
       BEGIN
       HISTORICO = HISTORICO||' DT.INICIO:'||OLD.DATA_INICIAL||'->'||NEW.DATA_INICIAL;
       END

   IF (OLD.DATA_FINAL <> NEW.DATA_FINAL) THEN
       BEGIN
       HISTORICO = HISTORICO||' DT.FIM:'||OLD.DATA_FINAL||'->'||NEW.DATA_FINAL;
       END

   IF (OLD.SITUACAO <> NEW.SITUACAO) THEN
       BEGIN
       HISTORICO = HISTORICO||' SIT:'||IIF(OLD.SITUACAO = '1', 'CONCLUIDO', IIF(OLD.SITUACAO = '2', 'CURSANDO', 'TRANCADO'))||'->'||IIF(NEW.SITUACAO = '1', 'CONCLUIDO', IIF(NEW.SITUACAO = '2', 'CURSANDO', 'TRANCADO'));
       END

   IF (HISTORICO <> '') THEN
       BEGIN

       HISTORICO = 'FORMACAO ALTERADA: '||HISTORICO;

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', NEW.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

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

   HISTORICO = ' FORMACAO EXCLUIDA: '||OLD.ID;

   IF (HISTORICO <> '') THEN
       BEGIN

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', OLD.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

------------------------------------------------------------------------------------------- EXPERIENCIA ----------------------------------------------------------------------------------


SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_experiencia_b02i for tbcurriculo_experiencia
active before insert position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = ' EXPERIENCIA INCLUIDA: '||NEW.ID;

   IF (HISTORICO <> '') THEN
       BEGIN

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', NEW.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger tbcurriculo_experiencia_b01u for tbcurriculo_experiencia
active before update position 0
AS
BEGIN
   IF(NEW.DATA_ATUALIZACAO IS NULL) THEN
       NEW.DATA_ATUALIZACAO = CURRENT_DATE;
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_experiencia_b02u for tbcurriculo_experiencia
active before update position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = '';

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

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

   IF (OLD.DATA_INICIAL <> NEW.DATA_INICIAL) THEN
       BEGIN
       HISTORICO = HISTORICO||' DT.INICIO:'||OLD.DATA_INICIAL||'->'||NEW.DATA_INICIAL;
       END

   IF (OLD.DATA_FINAL <> NEW.DATA_FINAL) THEN
       BEGIN
       HISTORICO = HISTORICO||' DT.SAIDA:'||OLD.DATA_FINAL||'->'||NEW.DATA_FINAL;
       END

   IF (OLD.SITUACAO <> NEW.SITUACAO) THEN
       BEGIN
       HISTORICO = HISTORICO||' SIT:'||IIF(OLD.SITUACAO = '1', 'DESLIGADO', 'ATUAL')||'->'||IIF(NEW.SITUACAO = '1', 'DESLIGADO', 'TRANCADO');
       END

   IF (HISTORICO <> '') THEN
       BEGIN

       HISTORICO = 'EXP.ALTERADA: '||HISTORICO;

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', NEW.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

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

   HISTORICO = ' EXPERIENCIA EXCLUIDA: '||OLD.ID;

   IF (HISTORICO <> '') THEN
       BEGIN

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', OLD.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^


------------------------------------------------------------------------------------------- QUALIFICACAO ----------------------------------------------------------------------------------

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_qualificacao_b02i for tbcurriculo_qualificacao
active before insert position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = ' QUALIFICACAO INCLUIDA: '||NEW.ID;

   IF (HISTORICO <> '') THEN
       BEGIN

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', NEW.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger tbcurriculo_qualificacao_bu0 for tbcurriculo_qualificacao
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = '';

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

   IF (HISTORICO <> '') THEN
       BEGIN

       HISTORICO = 'QUALIF.ALTERADA: '||HISTORICO;

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', NEW.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

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

   HISTORICO = ' QUALIFICACAO EXCLUIDA: '||OLD.ID;

   IF (HISTORICO <> '') THEN
       BEGIN

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', OLD.CURRICULO_ID,
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^


------------------------------------------------------------------------------------------- FORMACAO_DETALHE ----------------------------------------------------------------------------------

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_forma_detalhe_b02i for tbcurriculo_formacao_detalhe
active before insert position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = ' DISCIPLINA: '||NEW.id||' INCLUIDA NA FORMACAO: '||NEW.CURRICULO_FORMACAO_ID;

   IF (HISTORICO <> '') THEN
       BEGIN
           INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', (SELECT FIRST 1 T.CURRICULO_ID FROM TBCURRICULO_FORMACAO T WHERE T.ID = NEW.CURRICULO_FORMACAO_ID),
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_forma_detalhe_b01u for tbcurriculo_formacao_detalhe
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = '';

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

   IF (HISTORICO <> '') THEN
       BEGIN

       HISTORICO = 'DISCIPLINA: '||NEW.ID||' ALTERADA NA FORMACAO: '||NEW.CURRICULO_FORMACAO_ID||' '||HISTORICO;

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', (SELECT FIRST 1 T.CURRICULO_ID FROM TBCURRICULO_FORMACAO T WHERE T.ID = NEW.CURRICULO_FORMACAO_ID),
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

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

   HISTORICO = ' DISCIPLINA: '||OLD.ID||' EXCLUIDA DA FORMACAO: '||OLD.CURRICULO_FORMACAO_ID;

   IF (HISTORICO <> '') THEN
       BEGIN

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', (SELECT FIRST 1 T.CURRICULO_ID FROM TBCURRICULO_FORMACAO T WHERE T.ID = OLD.CURRICULO_FORMACAO_ID),
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

--------------------------------------------------------------------------------------EXPERIENCIA_DETALHE--------------------------------------------------------------------------

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_exp_detalhe_b02i for tbcurriculo_experiencia_detalhe
active before insert position 1
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = ' ATIVIDADE: '||NEW.id||' INCLUIDA NA EXP: '||NEW.CURRICULO_EXPERIENCIA_ID;

   IF (HISTORICO <> '') THEN
       BEGIN
           INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', (SELECT FIRST 1 T.CURRICULO_ID FROM TBCURRICULO_EXPERIENCIA T WHERE T.ID = NEW.CURRICULO_EXPERIENCIA_ID),
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

CREATE OR ALTER trigger ttbcurriculo_exp_detalhe_b01u for tbcurriculo_experiencia_detalhe
active before update position 0
AS
DECLARE VARIABLE HISTORICO VARCHAR(500);
BEGIN

   HISTORICO = '';

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

   IF (HISTORICO <> '') THEN
       BEGIN

       HISTORICO = 'ATIV: '||NEW.ID||' ALTERADA NA EXP: '||NEW.CURRICULO_EXPERIENCIA_ID||' '||HISTORICO;

       INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', (SELECT FIRST 1 T.CURRICULO_ID FROM TBCURRICULO_EXPERIENCIA T WHERE T.ID = NEW.CURRICULO_EXPERIENCIA_ID),
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^

SET TERM ^ ;

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

   HISTORICO = ' ATIVIDADE: '||OLD.ID||' EXCLUIDA NA EXP: '||OLD.CURRICULO_EXPERIENCIA_ID;

   IF (HISTORICO <> '') THEN
       BEGIN
           INSERT INTO TBHISTORICO (
       TABELA, TABELA_ID, USUARIO, IP, HISTORICO) VALUES (
      'TBCURRICULO', (SELECT FIRST 1 T.CURRICULO_ID FROM TBCURRICULO_EXPERIENCIA T WHERE T.ID = OLD.CURRICULO_EXPERIENCIA_ID),
      (SELECT FIRST 1 MON$USER FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
      (SELECT FIRST 1 MON$REMOTE_ADDRESS FROM MON$ATTACHMENTS WHERE MON$ATTACHMENT_ID = CURRENT_CONNECTION),
       :HISTORICO);
       END
END
^

SET TERM ; ^



