Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unique key question - How do you do it?
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00266795
Message ID:
00266885
Views:
23
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform