[Dbix-class] Increment MySQL field

Byron Young Byron.Young at riverbed.com
Mon May 18 20:00:21 GMT 2009


From: Андрей Костенко [mailto:andrey at kostenko.name] 
Sent: Monday, May 18, 2009 11:38 AM
To: DBIx::Class user and developer list
Subject: Re: [Dbix-class] Increment MySQL field

It is bad.
If my program have more than one thread:

first thread: SELECT balance FROM somewhere ( returns 150 )
second thread (which works at the same time): SELECT balance FROM somewhere ( returns 150 )
first thread: UPDATE something SET balance=250;
second thread: UPDATE something SET balance=250;




So wrap it in a transaction?

-Byron



On Mon, May 18, 2009 at 10:28 PM, Byron Young <Byron.Young at riverbed.com> wrote:
Ben Vinnerd wrote on 2009-05-15:
> Hey,
>
> I have the following SQL to increment a field by 100:
>
> update account set balance = balance + 100
>
> I can increment a field with DBIC, like so:
>
> $account->update({balance => \'balance + 100'});
>
> Is there a better/cleaner way of doing this in DBIC?
>
> Cheers,
>
> Ben
Ben, how about this?

 $account->update({balance => $account->balance + 100});

-Byron





More information about the DBIx-Class mailing list