Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Vfp50 - Auto Numbering
Message
De
21/04/1997 10:17:09
 
 
À
21/04/1997 10:11:41
Andrew Gray
Petrolink Services Ltd
Aberdeen, Royaume Uni
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00029060
Message ID:
00029067
Vues:
31
>>>I am trying to have new records AUTO NUMBER. My method
>>>is to index on a unique number field and add one number and that is the new number for the next record.
>>>Having problems like this...
>>>the first user adds a record and the computer issues a number 3, at the same time the second user adds a record and the computer issues a number 4. Then first user decides to abort and the second user saves.
>>>Now the second user has the number 4 for it's AUTO NUMBER and there is not a number 3 because the first
>>>use did not save. How can I best do a AUTO NUMBER system?
>>
>>The common way to create unique record id (number) is following:
>>1. System contains table 'Setup' with 2 fields: TableName C, Counter I.
>>2. When user requests for new record id, he runs procedure to:
>>- go to Setup and locate record by specific Tablename,
>>- lock this record (RLOCK),
>>- increment counter by 1,
>>- use ne counter for INSERT command,
>>- unlock Setup record.
>
>Cant improve on that, however it sounds like you are worried about having gaps in the saquence of IDs..
>If this is really going to be a problem, go ahead and append a new record when needed. If user 3 decides he doesnt want it, delete it. If you amend the "New ID" procedure so that it checks for a deleted record and recalls it before issuing a new ID, when user 5 comes along, they will get issued the previously created but unused "3".

Personally, I don't worry about gaps. Incrementing 'counter' by 1 will always guarantee uniqueness, and BTW gaps will exist here (if user/system cancels INSERT at the last moment).
Edward Pikman
Independent Consultant
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform