Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Key generation
Message
From
01/07/2002 10:19:25
Paul Robinshaw
Silkworm Technologies Limited
Macclesfield, United Kingdom
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Key generation
Miscellaneous
Thread ID:
00673857
Message ID:
00673857
Views:
54
Hi All,

I'm using Craig Berntson's key generation routine:
LPARAMETERS tcIDType, tnNumToGet

LOCAL llNotUsed, lnArea, lnRetVal

llNotUsed = .F.
llCanLock = .F.
lnArea = SELECT()

IF !USED( "idcount" )
	USE idcount IN 0
	llNotUsed = .T.
ENDIF
SELECT idcount
SET ORDER TO TAG table

*** Lock the entire table
DO WHILE !FLOCK()
ENDDO
	
SEEK UPPER( tcIDType )

IF FOUND()
	
	*** If we find the record then return this value
	lnRetVal = idcount.id
	REPLACE id WITH lnRetVal + IIF( EMPTY( tnNumToGet ), 1, tnNumToGet )
	
ELSE

	*** Record not found do create one
	INSERT INTO idcount ( id, table, tdesc ) VALUES ( 2, tcIDType )
	lnRetVal = 1

ENDIF

FLUSH
UNLOCK

IF llNotUsed
	USE IN idCount
ENDIF

SELECT( lnArea )

RETURN lnRetVal
Unfortunately, I'm getting duplicates as a result. They're really wierd as they're in batches, for instance I might get keys 316202,316203,316204,316205 for records 100-103 and then 316202,316203,316204,316205 for 104-107 and then the next key generated is 316206 and everything is synchronised again. Any help is appreciated.

Regards

Paul
Next
Reply
Map
View

Click here to load this message in the networking platform