ola a todos tenho a seguinte trigger abaixo:
CREATE OR ALTER trigger rdb$pafr07 for pafr07
active before insert or update position 0
AS
begin
NEW.MD5= HASH ( COALESCE( RDB$GET_CONTEXT('USER_SESSION', 'USUARIO' ), '') || COALESCE( NEW.IDREG07 , 0 ) ||
COALESCE( NEW.IDVENDA , 0 ) || COALESCE( NEW.DATA , ' / / ' ) || COALESCE( NEW.TIPO , '' ) ||
COALESCE( NEW.NROSERIE , '' ) || COALESCE( NEW.MFADICIONAL , '' ) || COALESCE( NEW.MODELOECF , '' ) ||
COALESCE( NEW.NROUSUARIO , '' ) || COALESCE( NEW.COO , '' ) || COALESCE( NEW.CCF , '' ) || COALESCE( NEW.GNF , '' ) ||
COALESCE( NEW.MEIOPAGTO , '' ) || COALESCE( NEW.VLPAGO , 0.00 ) || COALESCE( NEW.ESTORNO , '' ) ||
COALESCE( NEW.VLESTORNO , 0.00 ) || COALESCE( NEW.TIPODOC , '' ) || COALESCE( NEW.RECEBIMENTO , '' ) ||
COALESCE( NEW.EXPORTADO , '' ) || COALESCE( NEW.COD_CAI , 0 ) );
end;
ela é sempre executada quando qualquer operacao de insert ou update é feita. ate ai tudo bem.
sempre que entro no programa rodo o comando RDB$SET_CONTEXT('USER_SESSION', 'USUARIO' , 'TESTE')
os dados sao gravados normalmente, agora quando vou verificar os HASH como no comando abaixo, nao batem.
SELECT MD5, HASH( COALESCE( RDB$GET_CONTEXT('USER_SESSION', 'USUARIO' ), '') || COALESCE( IDREG07 , 0 )||
COALESCE( IDVENDA , 0 )||COALESCE( DATA , ' / / ' )||COALESCE( TIPO , '' )||
COALESCE( NROSERIE , '' )||COALESCE( MFADICIONAL , '' )||COALESCE( MODELOECF , '' )||
COALESCE( NROUSUARIO , '' )||COALESCE( COO , '' )||COALESCE( CCF , '' )||COALESCE( GNF , '' )||
COALESCE( MEIOPAGTO , '' )||COALESCE( VLPAGO , 0.00 )||COALESCE( ESTORNO , '' )||COALESCE( VLESTORNO , 0.00 )||
COALESCE( TIPODOC , '' )||COALESCE( RECEBIMENTO , '' )||COALESCE( EXPORTADO , '' )||
COALESCE( COD_CAI , 0 ))MD5_ATUAL FROM PAFR07
MD5 = CAMPO DA TABELA GRAVADO COM A TRIGGER
MD5_ATUAL = CAMPO CALCULADO NA GERACAO
ja tentei de varias formas, ja mandei mostrar o valor da variavel GET_CONTEXT e esta certa.
isso acontece apenas com 2 duas tabelas, o mais estranho que uso mesmo procedimento em outras e funciona.
segue abaixo codigo de insert que uso no firebird 2.5:
UPDATE OR INSERT INTO PAFR07 ( IDVENDA,DATA,TIPO,NROSERIE,MFADICIONAL,MODELOECF,NROUSUARIO,COO,
CCF,GNF,MEIOPAGTO,VLPAGO,ESTORNO,VLESTORNO,TIPODOC,RECEBIMENTO,EXPORTADO,COD_CAI )
VALUES( :IDVENDA,:DATA,:TIPO,:NROSERIE,:MFADICIONAL,:MODELOECF,:NROUSUARIO,:COO,
:CCF,:GNF,:MEIOPAGTO,:VLPAGO,:ESTORNO,:VLESTORNO,:TIPODOC,:RECEBIMENTO,:EXPORTADO,:COD_CAI )
MATCHING( NROSERIE, COO, CCF, GNF, MEIOPAGTO )
quem tiver um dica e puder ajudar agradeço.