Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Foxpro Multi-User : Primary key allocation - HELP!!
Message
From
30/09/2000 05:42:15
 
 
To
29/09/2000 13:28:31
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00422640
Message ID:
00423056
Views:
42
Hi Craig,

Heres my stored procedure which allocates primary keys and is giving occasional duplicates in a multi-user environment.

*-- Generate a Unique ID
FUNCTION NewID(tcAlias, tnDefaultValue, tcPrefix, tlLen)
LOCAL lcAlias, ;
lnID, ;
lcOldReprocess, ;
lnOldArea

lnOldArea = SELECT()

IF EMPTY(tcAlias)
lcAlias = UPPER(ALIAS())
ELSE
lcAlias = UPPER(tcAlias)
ENDIF

lcOldReprocess = SET('REPROCESS')

IF !USED("at_setup")
USE at_setup IN 0
ENDIF
SELECT at_setup

IF SEEK(lcAlias, "at_setup", "key_name")

*-- Lock until user presses Esc
SET REPROCESS TO AUTOMATIC

*-- We MUST obtain a lock here so we
*-- can be certain we have a reference
*-- to return.
DO WHILE !RLOCK()
ENDDO

REPLACE at_setup.value WITH at_setup.value + 1
lnID = at_setup.value
UNLOCK

SET REPROCESS TO lcOldReprocess

ELSE
*-- If seek failed, add new table to our setup table
*-- and set the default value being used.
APPEND BLANK
REPLACE at_setup.key_name WITH lcAlias, ;
at_setup.value WITH tnDefaultValue
lnID = tnDefaultValue
ENDIF

USE

SELECT (lnOldArea)

IF EMPTY(tcPrefix)
RETURN lnID
ELSE
RETURN tcPrefix + PADL(lnID, tlLen-LEN(tcPrefix), "0")
ENDIF

ENDFUNC

Any ideas greatly appreciated.

Paul.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform