Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique key question - How do you do it?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00266795
Message ID:
00266885
Vues:
22
Marcus,

I do it this way. I have a table named SysId with the following structure;
Field          Type      Contents
cTableName      C        Upper case table name
iNextID         I        The next key value to use for this table
My key generation code is similar to this;
* Get the next available PK
LPARAMETERS pcTable
IF EMPTY(pcTable)
	* Fail, no table name passed
	RETURN -1
ENDIF

pcTable = UPPER(pcTable)
LOCAL lnId, lcAlias, lcOrder
lcAlias = ALIAS()
IF USED("SysId")
	SELECT SysId
	lcOrder = ORDER()
ELSE
	SELECT 0
	USE data\SysId
	lcOrder = ""
ENDIF
SET ORDER TO TableName
SEEK pcTable
IF NOT FOUND()
	INSERT INTO SysId (TableName, NextId) VALUES (pcTable,1)
	SEEK pcTable
ENDIF
DO WHILE NOT RLOCK() && Ok, locks only short
ENDDO
lnId = NextId
REPLACE NextId WITH NextId + 1
UNLOCK
IF NOT EMPTY( lcOrder )
	SET ORDER TO &lcOrder
ENDIF
IF NOT EMPTY( lcAlias )
	SELECT ( lcAlias )
ELSE
	SELECT 0
ENDIF
RETURN lnId
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform