Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Database container damaged
Message
 
To
13/06/2002 01:31:19
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00636400
Message ID:
00667898
Views:
19
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
Previous
Reply
Map
View

Click here to load this message in the networking platform