Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
The easy way to form a primary key
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00541152
Message ID:
00541746
Vues:
23
>Hi!
>
>Thanks for the code. Unfortunately, I hove no much time to look to this yet, maybe later...

It's not a good 100% proven code, so it's not necessary for you to spend your time on it.
>
>>>Hi!
>>>
>>>TomDill (or TomasDill) is my Nickname there. I do not hide self and my real name is in my messages there.
>>>
>>>Correct, there might be a lot of problems related to multiple databases and free tables. We solved this problem by maintaining the same IDs table for all databases and it was a part of our data dictionaly (something like SDT). In other our applications we used different names for each different database and diferent function name for different database. Indeed tyhis have a lot of solutions. Just take the general idea, and extend it ...
>>>
>>
>>Here is our version, but it's buggy too :( Unfortunately, it's our general procedure (in wgUtility) and I don't have rights to change it without hassles of lots of e-mails...
>>
>>*!*****************************************************************
>>* PROGRAM	: LNEXTID.PRG
>>* AUTHOR	: DOUGLAS N. GRAY
>>* DESC		: Unique id generator.
>>* PARAMETER	: <None>
>>* CREATED	: 02/20/96
>>* MODIFIED	: 11/12/1999 - Changed PRIVATE to LOCAL, changed field names.
>>* MODIFIED  : Nadya Nosonovsky 08/22/2000 12:38:41 PM
>>*!*****************************************************************
>>procedure LNextID
>>lparameters tcalias
>>local lnoldarea,lnnextid, lcDBC, lcOldSetDBC, llOpened
>>llOpened=.t.
>>*--- Variable Setup
>>tcalias = iif(empty(m.tcAlias),upper(alias()),upper(tcalias))
>>lnoldarea = select()
>>lnnextid = 0
>>lcDBC=cursorgetprop('database',tcalias) && Return the name of owning database
>>if empty(lcDBC)
>>	=messagebox('You can not assign Next ID to the free table!',16,'Warning')
>>	return .f.
>>endif
>>lcOldSetDBC=set('database') && Save current status
>>if !dbused(lcDBC)
>>	open data (lcDBC)
>>	llOpened=.f. && Was not open before
>>endif
>>set database to (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 !used('NEXTID')
>>	use NEXTID in 0
>>	select NEXTID
>>else
>>	select NEXTID
>>endif
>>set order to table	&& NOTE: Index expression = UPPER(table)
>>
>>if !seek(tcalias)
>>	insert into NEXTID (table,id) values (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
>>		lnnextid=0
>>	endif
>>endif
>>
>>*--- Return to prior workarea.
>>select (m.lnoldarea)
>>if not llOpened
>>	close database
>>endif
>>if !empty(lcOldSetDBC)
>>	set database to (lcOldSetDBC)
>>endif
>>return lnnextid
>>>
>>>>>Hi!
>>>>>
>>>>>If you're interested, the way of doing it for VFP datatbase is described in FAQ article at the www.tek-tips.com site. We used the approach described there for years without any conflicts, but with some restrictions that are described in that FAQ article too.
>>>>>
>>>>
>>>>Are you using a pseudonym (?? - spelling) there? Hi, Tom :)
>>>>
>>>>You FAQ How to organize auto-increment key field in VFP?
>>>>faq184-259 has few minor problems... First of all, you need to ensure, that the NextID table is opened for the correct database. We had situations using code like yours, when incorrect NextID table was opened. So, I added a check for this into our lNextID function...
>>>>
>>>>>>Hi all,
>>>>>>
>>>>>>If you are interesting for a generation primary key problem, you can read an article "The easy way to form a primary key" at http://www.geocities.com/vhpcg/primkey.html
>>>>>>
>>>>>>Best regards,
>>>>>>Vladimir Trukhin
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform