Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unique ID
Message
From
30/08/2004 09:47:32
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
 
 
To
30/08/2004 09:39:50
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Miscellaneous
Thread ID:
00937563
Message ID:
00937568
Views:
13
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform