[Dbix-class] How to

Joerg Braun joerg at braun-senden.de
Tue Jun 19 13:29:49 GMT 2012


On Tue, 19 Jun 2012 10:01:41 +0530, Hardik Joshi <hardik at mavenvista.com>
wrote:
> Hello,
> 
> I have am working on one real time auction application where user used to
> enter new bid based on previous minimum bid value. There is possibility
> that two user will get same minimum value for their next bid. So I would
> like to restrict second user on select statement if already first user
has
> fired select statement and waiting for insert statement to complete.
> 

In another posting you had something with sleep 10sec. I do not think that
you want to lock a table longer than necessary. I would suggest another
approch. You are talking about auctions. So you have a table with articles
to bid for and maybe a table with user bids. So in pseudo code I would code
something like:

UPDATE article 
   set current_bid = 456
 where article_id = 123 
   and current_bid < <new_bid>

<new_bid> being the users bid. This might be another select. If the update
fails somebody was faster. If not the article itself is locked until you
did your inserts and commit.

Even the well known 3,2,1-company gives you one value and still someone
else might be higher if you bid to slow. That is life and has to be
accepted. Otherwise you let one or more bidders wait until the first (and
the second) has decided what to do or what not.

Just an idea.



More information about the DBIx-Class mailing list