Fórum Criar uma trigger pela aplicação #379590

16/06/2010

0

Estou tentando criar uma trigger usando o componente TIbquery, mas esta dando o seguinte erro : Unknown SQL DATA TYPE (0)!
Alguém pode me ajudar!

  Código: 
   sql:=' create or alter  trigger RPL_'+tabela+' for '+tabela+''+            ' after insert or update or delete '+            ' as '+            ' DECLARE VARIABLE C INT; '+            ' begin '+            '  if (inserting) then '+            ' begin '+            '    select count(*) from rpl_logs_espelhar '+            '       where tabela='''+tabela+''' AND CAMPO="'+campo+'" AND OPERACAO="I" and valor = new.'+campo+' INTO :C; '+            '    if (C=0) then '+            '    insert into rpl_logs_espelhar (ID,TABELA, CAMPO, OPERACAO, VALOR  ) '+            '    values (GEN_ID(auto_rpl,1),'''+tabela+''',"'+campo+'", "I", new.'+campo+');'+            '     end'+            ' if (updating) then '+            ' begin '+            '    select count(*) from rpl_logs_espelhar '+            '       where tabela='''+tabela+''' AND CAMPO="'+campo+'" AND OPERACAO="U" and valor = old.'+campo+' INTO :C; '+            '    if (C=0) then '+            '         insert into rpl_logs_espelhar (ID,TABELA, CAMPO, OPERACAO, VALOR  ) '+            '    values (GEN_ID(auto_rpl,1),'''+tabela+''',"'+campo+'", "U", old.'+campo+');'+            ' end '+            ' if (deleting) then '+            ' begin '+            '    select count(*) from rpl_logs_espelhar '+            '       where tabela='''+tabela+''' AND CAMPO="'+campo+'" AND OPERACAO="D" and valor = old.'+campo+' INTO :C; '+            '    if (C=0) then '+            '    insert into rpl_logs_espelhar (ID,TABELA, CAMPO, OPERACAO, VALOR  ) '+            '    values (GEN_ID(auto_rpl,1),'''+tabela+''',"'+campo+'", "D", old.'+campo+');'+            ' end '+            'end ; ';        IBQueryTabelas.SQL.Clear;        IBQueryTabelas.SQL.Add(sql);        IBQueryTabelas.ExecSQL;
Jean Silva

Jean Silva

Responder

Posts

17/06/2010

Carlos Mazzi

Em modo console do banco de dados, funciona?
Responder

Gostei + 0

18/06/2010

Jean Silva

Usei o IBSQL e funcionou! Obrigado.
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar