Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Unique ID
Message
De
30/08/2004 09:47:32
Jay Johengen
Altamahaw-Ossipee, Caroline du Nord, États-Unis
 
 
À
30/08/2004 09:39:50
Steven Dyke
Safran Seats USA
Texas, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00937563
Message ID:
00937568
Vues:
11
>What is the best method for creating a unique id for a record when multiole users are creating records at the same time?

We use the code below which keeps track of the assigned IDs for all tables.
*  Function......: GetNextID
*  Description...: Assigns the next highest primary key value.
*  Notes.........:
*  Parameters....: tcEntityName - name of the table to assign key value
*  Return........: integer


LPARAMETERS tcEntityName, tlClearFirst, tnNewValue
LOCAL liReturn

ASSERT PCOUNT() > 0
ASSERT TYPE('tcEntityName') = 'C'
ASSERT !EMPTY(tcEntityName)

tcEntityName = UPPER(ALLTRIM(tcEntityName))

SEEK tcEntityName ORDER ENTITYNAME IN NEXTID

liReturn = -1

IF FOUND('NEXTID')
	IF THISFORM.RecLock('NEXTID')
		IF tlClearFirst
			IF tnNewValue > 0
				liReturn = tnNewValue
			ELSE
				liReturn = 0
			ENDIF
			REPLACE NEXTID.ivalue WITH liReturn IN NEXTID
		ELSE
			liReturn = NEXTID.ivalue + 1
			REPLACE NEXTID.ivalue WITH liReturn IN NEXTID
		ENDIF
		UNLOCK IN NEXTID
	ENDIF
ELSE
	liReturn = 1
	INSERT INTO NEXTID (centitynam, ivalue) VALUES (tcEntityName, liReturn)
ENDIF

RETURN liReturn
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform