Welcome Guest, Not a member yet? Register   Sign In
how to catch db error
#7

(10-14-2019, 04:42 AM)amansusanto Wrote:
(10-14-2019, 04:21 AM)InsiteFX Wrote: A better way would be to create a separate table for holding the last id's.

table last_id
blue_id
yellow_id
green_id

When you create the users record assign the correct id with an increment method.

still cannot, because data entry by many people / user

it could be red inputted simultaneously by several users

So fundamentally, you have a race condition.

The cleanest way to solve this is to use the primary key to store the row in the database, the use a lock to fix up within the transaction the colored tags.

We do this when creating invoice numbers, create a second table with the last number in, lock it as part of the transaction and then add a 1 to the stored value. Then at the end of the transaction, update the value in the companion table.

This way, you can block other accesses to the critical value, giving you access. when the transaction completes, it is unlocked and the next one can proceed.


Be warned, this will not scale to large numbers of users, as at some point, the queued transactions will begin to time out.
Reply


Messages In This Thread
how to catch db error - by amansusanto - 10-11-2019, 07:33 PM
RE: how to catch db error - by InsiteFX - 10-12-2019, 03:58 AM
RE: how to catch db error - by tp45 - 10-12-2019, 07:44 PM
RE: how to catch db error - by amansusanto - 10-13-2019, 07:26 PM
RE: how to catch db error - by InsiteFX - 10-14-2019, 04:21 AM
RE: how to catch db error - by amansusanto - 10-14-2019, 04:42 AM
RE: how to catch db error - by Chroma - 10-14-2019, 08:26 AM
RE: how to catch db error - by amansusanto - 10-15-2019, 08:28 PM
RE: how to catch db error - by InsiteFX - 10-16-2019, 04:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB