Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Who is locking my table?
Message
From
21/08/2001 10:43:23
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00546730
Message ID:
00546737
Views:
19
>Hallo everyone
>I have 2 questions that I would be very happy to get answers to:
>Is there any command/function in VFP I can use to automatically fill a primary/candidate key field with a new unique number when I save a new record? Or must I make my own function?
>If a network user is locking a record or table and not release it, is there a way to figure out who it can be. So I can call him, and tell him to release the lock.
>I hope you understand what I mean.
>Thanks in advance
>/Kjell

My version. Save this function in database stored procedures. See comments in function.
**********************************************************************
FUNCTION SERIALNUMBER(tnSequence)
	* Get serial number. Used mainly to generate primary keys.
	* The easiest way to achieve this is to call this function from a fields default value.
	* This function accesses table SerialNumber. Fields: Sequence C(30), NextNum I.
	tnSequence = lower(tnSequence)
	local lnSelect
	lnSelect = select()
	if used("serialnumber")
		select serialnumber
	else
		select 0
		use serialnumber
	endif
	set order to "sequence"
	seek padr(tnSequence, len(sequence))
	if not found()
		append blank
		replace sequence with tnSequence, nextnum with 1
	endif
	local lnReturnValue
	if lock()
		lnReturnValue = nextnum
		replace nextnum with nextnum + 1
	else
		lnReturnValue = -1
	endif
	unlock
	select (lnSelect)
	return lnReturnValue
ENDFUNC
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform