Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Strange behavior of a Stored Procedure in a transaction
Message
De
25/11/2002 09:02:39
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Strange behavior of a Stored Procedure in a transaction
Divers
Thread ID:
00726393
Message ID:
00726393
Vues:
46
Hi group.

This stored procedure generates primary keys automatically for our system DB.
FUNCTION _st_Gw_GeraId (tcCampo)
	LOCAL lnId,lcArq,lcTabela,llBuff,lnReprocessOld

	lnReprocessOld = SET("Reprocess")
	SET REPROCESS TO 3 SECONDS
	lcTabela = ALIAS()
	lcArq    = "gw_gera_id"
	lnId     = -1
	tcCampo  = UPPER(tcCampo)
	
	
	IF !USED(lcArq)
		USE (lcArq) IN 0 SHARED 
	ENDIF 
	
	SELECT (lcArq)
	GO TOP IN (lcArq) 
	
	LOCATE FOR ALLTRIM(&lcArq..pk) == ALLTRIM(tcCampo)

	IF NOT FOUND()
		APPEND BLANK IN (lcArq)
		REPLACE &lcArq..pk     WITH tcCampo
		REPLACE &lcArq..tabela WITH lcTabela
	ELSE
		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 lnReprocessOld
			RETURN -1
		ENDIF
	ENDIF 
	
	lnId = &lcArq..nextval
	REPLACE &lcArq..nextval WITH &lcArq..nextval + 1
	UNLOCK IN (lcArq)
	USE IN (lcArq)
	SELECT (lcTabela)
	SET REPROCESS TO lnReprocessOld

	RETURN lnId
ENDFUNC 
It works perfectly until 2 stations engage in a transaction using the same table.

The test uses 2 stations; One station issues an append blank and waits. The other station then issues an append blank of its own. The problem is that the SP returns an Error mEssage, because it doesn´t unlock the table indicated by lcArq. This occurs only in a Transaction. What to do?

TIA,
Pablo Márcio de Oliveira

Inside the scream is silent, inside it must remain
Répondre
Fil
Voir

Click here to load this message in the networking platform