Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multi-user access problem
Message
 
To
24/02/1998 07:24:37
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00080726
Message ID:
00080826
Views:
20
>I encountered a problem with solving update conflicits.
>A good example may be a ware stock.
>
>I use Record Bufforing for managing my stock table. When an operator
>decides to save entered data I issue TABLEUPDATE(.T.,.F.).
>
>The problem arises when two operators manipulate the stock of the same
>item simultanously. For example one of them is doing an invoice and
>selling the item to somebody, another one is entering a delivery of the
>same item to the stock. Than only last operation is saved and the final
>quatity of the item on stock in wrong.

Marcia,

You have a fairly complex problem here and it is not simply the conflict. TableUpdate is the commadn you need along with CURVAL() and OLDVAL(). Something like this;

IF NOT TableUpdate(.T.,.F.,"Inventory")
* A conflict
* Get the error
AERROR(laError)
IF laError(1) = 1585
* Update conflict
IF RLOCK()
lnCurInv = CURVAL(nQuantity)
REPLACE nQuantity WITH lnCurInv - Invoice.Quantity
TableUpdate(.T.,.T.)
UNLOCK
ELSE
* Cannot save
TableRevert(.T.,"Inventory")
ENDIF
ELSE
* Some other error occured
ENDIF
ENDIF

This code attampts an update and if it fails it checks to see if the failure is due to a conflict. If it si it locks the record to prevent anyone else from getting in, then recalculates the quantity on hand based on CURVAL() which the value in teh table now and forces an update. It then unlocks the record.

Of course you would need to put in some code to handle the other errors that may occur and to handle the inability to lock the record.
Previous
Reply
Map
View

Click here to load this message in the networking platform