Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Vfp50 - Auto Numbering
Message
De
21/04/1997 10:20:30
 
 
À
21/04/1997 10:04:38
Matt Mc Donnell
Mc Donnell Software Consulting
Boston, Massachusetts, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00029060
Message ID:
00029068
Vues:
32
>>
>> >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.
>
>I had a simlar question last week and Arnon gave me what I believe to be
>a better solution, particularly with a high volume mutli-user
>environment.
>
>BEGIN TRANSACTION
> USE setup EXCL
> {get record id and step}
> USE IN setup
>END TRANSACTION
>
>This method guarantees that no IDs will be duplicated. In addition, you
>can set up a rule in your DBC to make the index unique (primary) thereby
>preventing the entry of a duplicate id number.
>
>HTH

Matt, your method will surely work. The only problem is exclusive opening especially if it's part of dbc. RLOCK() will provide uniqueness the same way and with less overhead.
>
>--
Edward Pikman
Independent Consultant
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform