Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generating Unique ID
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00586682
Message ID:
00586784
Views:
23
Hi Sergey,

Regardless of the alias I need to add records to the AllFunctions table. If I open this table under AllFunctions alias, my code works, if under different alias, it gives SP error (with only OK and Help functions available). I know, it fails on line cursorgetprop. I don't see right now a correct resolution of this problem (I'll think more while sleeping :)). Just would be grateful, if you have ideas of fixing this problem.

See my reply to Steve for more detailed explanation, why I want to check owning database name.


>Hi Nadya,
>
>I don't see anything wrong with your code. It doesn't matter under what alias you open table AllFunctions under because in the end result all records are added to that table. That's why all id's should be generated for AllFunctions table and not the alias it's open under. Does it make sense or I'm missing something?
>
>>>What if it's open two or more times using USE AGAIN? Which of aliases would you want?
>>>
>>
>>Oops! Haven't thought about this possibility...
>>
>>So, do you have suggestions of fixing my SP code?
>>
>>Thanks a lot in advance.
>>
>>>>Hi everybody,
>>>>
>>>>Here is my SP code:
>>>>
>>>>function GetNextID
>>>>lparameters tcAlias
>>>>local lnOldArea,lnNextID, lcDBC, lcOldSetDBC, llOpened, lcCurAlias
>>>>llOpened=.t.
>>>>*--- Variable Setup
>>>>lcCurAlias=upper(alias())
>>>>if empty(m.lcCurAlias)
>>>>	=messagebox("No table open...",16,"Error")
>>>>	return null
>>>>endif
>>>>tcAlias = iif(empty(m.tcAlias),m.lcCurAlias,upper(m.tcAlias))
>>>>lnOldArea = select()
>>>>lnNextID = 0
>>>>lcDBC=cursorgetprop('database',m.tcAlias) && Return the name of owning database
>>>>if empty(m.lcDBC)
>>>>	=messagebox('You can not assign Next ID to the free table!',16,'Warning')
>>>>	return null
>>>>endif
>>>>lcOldSetDBC=set('database') && Save current status
>>>>if !dbused(m.lcDBC)
>>>>	open data (m.lcDBC)
>>>>	llOpened=.f. && Was not open before
>>>>endif
>>>>set database to (m.lcDBC) && Make this DBC current
>>>>*--- Go to NextID Database to assign the next unique ID
>>>>*--- Assumes the you are sitting in the correct DBC.
>>>>if !OpenTble(addbs(justpath(m.lcDBC))+juststem(m.lcDBC)+"!"+"NextID",,,"Table")
>>>>	=messagebox('NextID could not be opened!',16,'Warning')
>>>>	return null
>>>>endif
>>>>select NextID
>>>>if !seek(m.tcAlias)
>>>>	insert into NextID (table,id) values (m.tcAlias,1)
>>>>	lnNextID = 1
>>>>else
>>>>*--- RLOCK will attempt the lock indefinately, because it would be bad to return 0 (the alternative).
>>>>*--- User will be able to cancel attempt if in a deadlock by pressing the ESC key.
>>>>	if rlock()
>>>>		replace NextID.id with NextID.id + 1
>>>>		lnNextID = NextID.id
>>>>		unlock
>>>>	else
>>>>		return null
>>>>	endif
>>>>endif
>>>>*--- Return to prior workarea.
>>>>select (m.lnOldArea)
>>>>if not m.llOpened
>>>>	close database
>>>>endif
>>>>if !empty(m.lcOldSetDBC)
>>>>	set database to (m.lcOldSetDBC)
>>>>endif
>>>>return m.lnNextID
>>>>
>>>>The problem is, what if I open table under different alias? In default value I have GetNextID('AllFunctions').
>>>>
>>>>So, my problem is to find out under which alias AllFunctions table is opened. I'm having brain loss at this moment. How can I find out the alias by fullpath table name?
>>>>
>>>>Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform