checkout_process.php and race condition

heddesheimer <[email protected]>
Newsgroups gmane.comp.web.oscommerce.suggestions
Message-ID <997fd816db458f18a2b645235560fa46@osCommerce-Forums>
This message was sent from: Suggestions and Proposals
http://forums.oscommerce.com/viewtopic.php?p=175620#175620
----------------------------------------------------------------

Hi,
I found a potential problem with the code in checkout_process.

In a first query, the stock value will be retrieved via SQL SELECT, then the new stock value is calculated from this stock value and the number of items ordered. After that, the new value is stored via SQL UPDATE.

Is'nt there a potential problem if another customer orders the same item and checks out at the same time? I have learned that it would be a good idea to lock the table between these two SQL statements. Otherwise it would also be possible to use another approach by not using a pre-calculated stock value and to calculate the new stock value in the UPDATE statement.

Like this: 
[code]
UPDATE products set products_qantity = products_quantity - $order->products[$i]['qty'] where products_id = ...
[/code]

What do you think? Should I change the code accordingly or did I overlook something?

Marian
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.