Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Avoiding Dublicate Field entries in a multi-user applica
Message
From
20/02/1998 12:30:03
 
 
To
20/02/1998 11:47:05
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00080125
Message ID:
00080141
Views:
25
>>Am a Visual Foxpro beginner with yet another question.. I need you help on again..
>>
>>
>>I am working on an application that tracks work orders. The work order number field entry is a function of the RECNO() and I want it to be incremented automatically by the program not by the user. I put a default expression for the field in the table structure and also have that field as a Primary index. Well, it seems to be O.K and it's incrementing as I want. BUT this afternoon, I was testing to see what happens when two users opens the database/Table at about the same time to add records. I noticed that both users Work Order No. fields contains the same entries (I suppose 'cos the RECNO() presented to both users are the same). Although they can both have the same values in the wk order field only one can save because of the primary key nature of the field. My problem seems to be how to get different users enter data into the same database with different work order numbers.
>>any idea???
>>Please help!!! I would be grateful...
>
>First I wouldn't suggest recno() as a PK. Assuming still you want it :
>-Table where recno() is taken should be a another table.
>-Whenever you want to take recno(), lock the table, get your recno() and release lock.
>-For multiple tables, instead of just getting a recno(), keep an id at that particular table, for each of the tables, ie:
>Table_id, Lastrecno
>mycustomer 12
>myorders 23
>...
>You can see an example for this in solutions.app and tastrade.app (Both can be find in help\sample applications).
>-When you will get the recno() or id, lock the record or table. To prevent and endless lock attempt, "set reprocess to 1", try lock, if not locked continue trying lock with some delay.
>Cetin

Here's another method I've used. The advantage is that you don't have to do extra record locking and keep track of last-used ID's. The disadvantage is that you don't get sequential numbers.

Store julian date or year+month+day in the order number field. Then add the 24-hour time with seconds. The format would be YYYYMMDDHHmmSS. If you're indexed on this field, everything will be in date/time order. If you have a lot of users, you may want to add a couple of digits from the random number generator, Rand(), to avoid two people hitting the Enter key at the same second.

But, If you need sequential numbers or need to follow an existing format, you can't use this method.

Allen
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform