Criar uma trigger pela aplicação
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;
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
Curtidas 0
Respostas
Carlos Mazzi
16/06/2010
Em modo console do banco de dados, funciona?
GOSTEI 0
Jean Silva
16/06/2010
Usei o IBSQL e funcionou! Obrigado.
GOSTEI 0