[firebase-br] Attempt to store duplicate value (visible to active transactions) in unique index
Eduardo Jedliczka
edujed em gmail.com
Qui Jan 27 16:02:54 -03 2011
Neste caso, ao invés de alterar diretamente as tabelas de sistema
(algo que será 100% proibido no FB 3.0) não seria mais saudável,
dropar a tabela e recriar ?
==========================
Eduardo Jedliczka
Apucarana - Pr
==========================
Em 26 de janeiro de 2011 17:18, Hélio Oliveira <hpensador em gmail.com> escreveu:
> Boa tarde Colegas!
>
> Este erro ocorre durante a tentativa de criação de uma chave primaria em uma
> tabela. Em um post anterior o Carlos Cantu respondeu indicando um artigo
> onde o autor informa que este erro ocorre devido a duplicidade de registros
> (chave-primaria) porém não é este o meu problema conforme demonstro abaixo
> (Script de atualização completo.)
>
> Desculpem sei que a mensagem ficou um tanto quanto longa...
>
> connect c:\Diretorio\BASE.gdb user "SYSDBA" password "masterkey";
> CREATE TABLE tabela_aux(
> MATRICULA INTEGER,
> MES INTEGER,
> ANO INTEGER,
> SEQUENCIA INTEGER,
> PROVENTO INTEGER,
> REFERENCIA NUMERIC(6,2),
> VALOR NUMERIC(12,2),
> F_V VARCHAR(1)
> );
> commit work;
>
> insert into tabela_aux select * from variavel where valor is not null and
> valor > 0;
> commit work;
>
> delete from variavel;
> commit work;
>
> update RDB$RELATION_FIELDS set
> RDB$NULL_FLAG = 1
> where (RDB$FIELD_NAME = 'MATRICULA')
> and (RDB$RELATION_NAME = 'VARIAVEL');
> commit work;
>
> update RDB$RELATION_FIELDS set
> RDB$NULL_FLAG = 1
> where (RDB$FIELD_NAME = 'MES')
> and (RDB$RELATION_NAME = 'VARIAVEL');
> commit work;
>
> update RDB$RELATION_FIELDS set
> RDB$NULL_FLAG = 1
> where (RDB$FIELD_NAME = 'ANO')
> and (RDB$RELATION_NAME = 'VARIAVEL');
> commit work;
>
> update RDB$RELATION_FIELDS set
> RDB$NULL_FLAG = 1
> where (RDB$FIELD_NAME = 'SEQUENCIA')
> and (RDB$RELATION_NAME = 'VARIAVEL');
> commit work;
>
> update RDB$RELATION_FIELDS set
> RDB$NULL_FLAG = 1
> where (RDB$FIELD_NAME = 'PROVENTO')
> and (RDB$RELATION_NAME = 'VARIAVEL');
> commit;
>
> alter table variavel add constraint pk_variav primary key (matricula, mes,
> ano, sequencia, provento);
> commit;
>
> set term ^;
> create or alter procedure popula_variavel
> as
> declare variable matricula integer;
> declare variable mes integer;
> declare variable ano integer;
> declare variable sequencia integer;
> declare variable provento integer;
> declare variable referencia numeric(6,2);
> declare variable valor numeric(12,2);
> declare variable f_v varchar(1);
> begin
> for select matricula, mes, ano, sequencia, provento, referencia, valor, f_v
> from tabela_aux
> where valor is not null
> and valor > 0
> into :matricula, :mes, :ano, :sequencia, :provento, :referencia, :valor,
> :f_v do
> begin
> if (not exists(select v.matricula,
> v.mes,
> v.ano,
> v.sequencia,
> v.provento
> from variavel v
> where v.mes = :mes
> and v.ano = :ano
> and v.sequencia = :sequencia
> and v.matricula = :matricula
> and v.provento = :provento)) then
> insert into variavel (matricula, mes, ano, sequencia, provento,
> referencia, valor, f_v)
> values (:matricula, :mes, :ano, :sequencia, :provento, :referencia,
> :valor, :f_v);
> end
> end^
> commit work^
> set term ^;
>
> execute procedure popula_variavel;
> commit work;
>
> drop procedure popula_variavel;
> commit work;
>
> --
> []'s,
>
> Hélio Oliveira
> Bel. Ciência da Computação
> Técnico em Contabilidade
> e-mail : hpensador em gmail.com
> Skype : hpensador
> www.hpensador.net
> (71) 9975-9176
>
>
> ______________________________________________
> FireBase-BR (www.firebase.com.br) - Hospedado em www.locador.com.br
> Para saber como gerenciar/excluir seu cadastro na lista, use:
> http://www.firebase.com.br/fb/artigo.php?id=1107
> Para consultar mensagens antigas: http://firebase.com.br/pesquisa
>
Mais detalhes sobre a lista de discussão lista