Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Capturing last records
Message
De
09/02/2003 16:22:35
 
 
À
09/02/2003 15:20:35
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00751200
Message ID:
00751211
Vues:
18
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?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform