Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Database container damaged
Message
 
À
13/06/2002 01:31:19
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00636400
Message ID:
00667898
Vues:
17
Arita,

I don't know why your code doesn't work but here is how I do it.

Oner table named NextID with two fields TableName C(120) and LastID I there is an index on UPPER(cTableName). There is one record for each table in the system. In the Database each table yhas a field for it's primary key that is marked as the Primary key. The Default value for that field is NextID("TableName"). Belwo is my NextID function's code;
LPARAMETERS pcTableName
IF EMPTY( pcTableName )
	RETURN .NULL.
ELSE
	pcTableName = UPPER(ALLTRIM(pcTableName))
ENDIF

LOCAL lcAlias, liNextId, lnOldBufferMode, lnCounter, lnRet
lcAlias = ALIAS()
IF NOT USED( "NextID" )
	SELECT 0
	USE Data\NextID
ELSE
	SELECT NextID
ENDIF
lnOldBufferMode = CursorGetProp("BUFFERING","IntIds")
* shut off buffering
CursorSetProp("BUFFERING", 1,"IntIds")
SET ORDER TO TableName
SEEK pcTableName
DO WHILE NOT FLOCK() AND lnCounter < 10000
	lnCounter = lnCounter + 1
ENDDO
IF NOT FLOCK()
	RETURN .NULL.
ENDIF
IF NOT FOUND()
	* Make a record
	APPEND BLANK
	REPLACE TableName WITH pcTableName, LastId WITH 1
	lnRet = 1
	UNLOCK
ELSE
	* Use the record that is there
	lnRet = LastId + 1
	REPLACE LastId WITH lnRet
	UNLOCK
ENDIF
IF NOT EMPTY( lcAlias )
	SELECT ( lcAlias )
ELSE
	SELECT 0
ENDIF
RETURN lnRet
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform