Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Erro na atualização...
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00766198
Message ID:
00766518
Vues:
23
This message has been marked as the solution to the initial question of the thread.
Consegui a solução :

O erro acontecia que quando a SP abaixo era chamada de dentro de uma transação, por mais de uma vez. Resolvi criando um objeto Session e mudando a DataSession de uso para executar a SP.

O código corrdido ficou desta Maneira :
FUNCTION _st_Gw_GeraId (tcCampo)
	LOCAL lnId,lcArq,lcTabela,lnRepro,llBuff
	LOCAL loSession,lnOldSession,lnIdSession

	m.lnOldSession = SET("Datasession")           && salvando a DataSession Atual
	m.loSession    = CREATEOBJECT("Session")      && cria um objeto Session
	m.lnIdSession  = loSession.DataSessionId      && Pega a SessionId do objedto
	
	SET DATASESSION TO m.lnIdSession              && Muda para a nova datasession para não sofrer com as Transações.
	
	m.lcTabela     = ALIAS()
	m.lcArq        = "gw_gera_id"
	m.lnId         = -1
	m.tcCampo      = UPPER(m.tcCampo)
	m.lnRepro      = SET("Reprocess")
	
	SET REPROCESS TO 5 SECONDS && espera no máximo por 5 segundos para travar um registro.
	
	IF !USED(m.lcArq)
		USE (m.lcArq) IN 0 SHARED  
	ENDIF 

	SELECT (lcArq)
	GO TOP IN (lcArq) 

	LOCATE FOR ALLTRIM(&lcArq..pk) == ALLTRIM(m.tcCampo)
	
	IF NOT FOUND()
		INSERT INTO (lcArq) (pk,tabela) VALUES (m.tcCampo,m.lcTabela)
		LOCATE FOR ALLTRIM(&lcArq..pk) == ALLTRIM(m.tcCampo)
	ENDIF
	IF !RLOCK(lcArq)		&& criar uma rotina para possivel erro.
		ERROR [Registro travado por outro usuário, não permitindo a geração da Chave primária],[Informe a controplan]
		SET REPROCESS TO lnRepro
		RETURN -1
	ENDIF

	m.lnId = &lcArq..nextval
	REPLACE &lcArq..nextval WITH &lcArq..nextval + 1
	UNLOCK IN (lcArq)
	USE IN (lcArq)
         
         *** restaura o ambiente anterior ***
	SET REPROCESS TO m.lnRepro                
	SET DATASESSION TO m.lnOldSession
	RELEASE loSession 

	IF NOT EMPTY(m.lcTabela)
	   SELECT (lcTabela)
	ENDIF


	RETURN lnId
ENDFUNC 
Paulo Cesar Carneiro
desenvolvimento@controplan.com.br


"My God, what have we done?"
-- Capt. Robert Lewis, co-pilot of the Enola Gay, recalling the moment the atomic bomb exploded over Hiroshima

At 8:15 a.m. on August 6 1945
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform