Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Capturing last records
Message
From
09/02/2003 16:22:35
 
 
To
09/02/2003 15:20:35
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00751200
Message ID:
00751211
Views:
11
Add this procedure to a database if you want to get a clean PK:
FUNCTION NextID(tcAlias)
	LOCAL nSelect, nReprocess, nRetVa

	IF PCOUNT() < 1
		*-- Nothing passed in, use current alias
		cAlias = ALLTRIM(UPPER(ALIAS()))
	ELSE
		cAlias = ALLTRIM(UPPER(m.tcAlias))
	ENDIF
	
	nSelect    = SELECT()
	nReprocess = SET('Reprocess')
	nRetVal    = NULL
	
	*-- Lock until user presses Escape
	SET REPROCESS TO AUTOMATIC
	
	IF NOT USED('IDs')
		USE IDs IN 0 SHARED
	ENDIF
	
	SELECT IDs
	LOCATE FOR ALLTRIM(TableName) == m.cAlias
	IF NOT FOUND()
		*-- Row not found, add it now
		INSERT INTO IDs (tablename, nextid) VALUES(cAlias,0)
	ENDIF
	
	IF RLOCK()
		REPLACE nextid WITH nextid + 1 IN ids
		nRetVal = ids.nextid
		UNLOCK
	ENDIF
	
	SET REPROCESS TO nReprocess
	SELECT (nSelect)
	
	RETURN m.nRetVal
The default value for the pk column of a database column would be NextID()

>Can anyone provide a program or method that would allow me to ensure that I retrieve the very last record of my databases to ensure that I have a clean primary key?
Previous
Reply
Map
View

Click here to load this message in the networking platform