Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ID field
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01170010
Message ID:
01170815
Views:
9
>>>Hi everybody,
>>>
>>>AFAIK there is no way in multi-user environment to have ID field incremented correctly without using extra table to keep the last ID (if we're not using autoincrement field). Using go bottom, grab the last number and start from there doesn't prevent two users from taking the same ID. Even if we put a check right after for the existance of ID.
>>>
>>>What do you think? Given only one table and no auto-increment is it possible to correctly auto-increment in multi-user environment?
>>>
>>>Thanks.
>>
>>I have another idea.
>>You always can create a new table when you start the application. Then you could use this table as key generator. That way first user started the application will create this table.
>>
>>lcTableName = path_to_data_folder+[MyKeyGenTable]
>>IF EMPTY(SYS(2000),lcTableName+[.DBF])
>>   CREATE TABLE (lcTableName) FREE (NewKey I)
>>   SELECT MAX(Id)+1 FROM Invoice INTO ARRAY laInvKey
>>   INSERT INTO (lcTableName) VALUES (laInvKey[1])
>>   USE IN SELECT([MyKeyGenTable])
>>   USE IN SELECT([Invoice])
>>ENDIF
>>
>
>Thanks, this seems like a good idea. I also agree with Fabio and Peter, so either one of these ideas should work.

Yes, I like Peters's one more than mine :-)
You could create another table in with you could store canceled invoices. Then when you generate new one first search in that table, if not found and generate new one from the key table. This is of course if you use a Key Table. That will prevent you to keep key table locked, have an ID when the user create the invoice (not when user save it). When the user Cancel save just add this number in the table with unused IDs.
Of course this is applicable only if you can have bigger ID for smaller dates.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform