There are many ways to handle this.
You might get the current quantity on hand, and compare to orderqty
update inventory set qtyonhand=qtyonhand - orderqty where
itemno='myitemno' and qtyonhand=myqtyonhand
If the query fails, repeat until qtyonhand < orderqty or update
succeeds.

Every hour or so, go through your shopping carts, and
post ordered qty back into inventory for all abandoned carts.

Daniel B I wrote:
> 
> Please, any idea how to manage concurent requests,
> for example like in a shopping cart?
> 
> Scenario:
> 
> 1. I have a counter A (a field in a database row), set to 1, so A=1
> 
> 2. A client wants 1 unit from A , it checks and it's OK,
>    there is available.
> 
> 3. Another client wants 1 unit from A, it checks, and it's OK,
>    because first client did not subtracted yet 1 unit from A
> 
> 4. The first client decreases A, so A=0
> 
> 5. The scond client decreases A, so A=?... some garbage...
> 
> Any idea how to fix this transaction problem? If A is locked by the
> first client in order to fix this problem, there is another question (the
> really one!):
> 
> If the program terminates unexpectedly, what about A?
> It remains locked forever, and the second client cannot use it
> anymore ?
> 
> thanx!
> any idea really apreciated!
> 
> Daniel BI
> 
> ---------------------------------------------------------------------
> Before posting, please check:
>    http://www.mysql.com/manual.php   (the manual)
>    http://lists.mysql.com/           (the list archive)
> 
> To request this thread, e-mail <[EMAIL PROTECTED]>
> To unsubscribe, e-mail 
><[EMAIL PROTECTED]>
> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to