Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Multi User Locking in Sql selects
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01516987
Message ID:
01517041
Views:
45
Hi Viv, thanks for replying.

....User A : Update Inventory Set Balance = Balance +5
....User B: Update Inventory Set Balance = Balance +7

Is there a Sql Command like---> Update Inventory Set Balance = Balance +5
which replaces whatever Balance is in Sql with the Balance + 5
If there is, I think that would work fine

I have only ever used a sSql Update as:
Update Inventroy Set Balance = X which replaces the Balance with X

But in my Case, Say I am User B, when i Initially took the Balance it was 100, and now I am replacing it with 100 + 7
but User A has already increased it to 100 + 5 = 105

Regards,
Gerard






>>I have following scenario and wonder how to handle it in Sql (In VFP I would have used FLOCK)
>>
>>Inventory Balance = 100
>>
>>User A Selects Out from Inventory Table
>>Uses the 100, Does 'stuff' with Inventory Balance whcih Takes 5 Minutes, and needs to add 5 to the 'Curent ' Balance
>>(If I use a Sql Update Balance woukd be changed to 105 (100 + 5)
>>
>>User B Selects out from Inventory Table at same time as user A (Balance= 100)
>>Uses the 100, Does 'stuff' with Inventory which Takes 7 Minutes, and needs to add 7 to the Balance () (whatever it happens to be now
>>(If I use a Sql Update , Balance would be changed to 107 (100 + 7)
>> ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>>
>>What I really want the new balance to be is 100 + 5(User A) + 7 (User B) i.e. 112
>>
>>Do I still use some form of Locking or is there 'some other way' to do this in SQL
>
>In the situation you describe I don't see the problem:
>User A : Update Inventory Set Balance = Balance +5
>User B: Update Inventory Set Balance = Balance +7
>
>I think what you are really worried about is the scenario where they both want, for example, to deduct 80 from the Balance?
>In that case you proabably have to make a value judgement as to how often this could occur. If rarely then either check that the backend balance is still the same as when the user retrieved it. If it is not then you have to decide whether the transaction is still valid or should be rejected.
>
>I'm no SQL expert but I don't think there is any equivalent of VFPs RLOCK() (I assume you would use that rather then FLOCK()) and the 'roll your own' ideas I've seen look cumbersome, risky and best avoided.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform