[Dbix-class] Insert or Update (was ANNOUNCE: 0.08099_08)

Andreas Mock andreas.mock at drumedar.de
Fri Apr 10 20:23:36 GMT 2009


> -----Ursprüngliche Nachricht-----
> Von: "Peter Corlett" <abuse at cabal.org.uk>
> Gesendet: 09.04.09 15:39:05
> An: "DBIx::Class user and developer list" <dbix-class at lists.scsys.co.uk>
> Betreff: Re: [Dbix-class] ANNOUNCE: 0.08099_08 (0.08100_RC2)

> The current implementation does a SELECT followed by an INSERT or UPDATE as
> appropriate. This introduces a race condition. The whole thing is a critical
> section and needs to be wrapped in a transaction or savepoint.

O.k. I asked why you have to use savepoints, because I thought you can
also use transactions.


> I implemented it by starting a savepoint, then just trying the INSERT. If
> that fails (normally due to duplicate UNIQUE keys) then the savepoint is
> rolled back and the SELECT and UPDATE is done as before. After the UPDATE,
> the savepoint is committed.

Why do you have to do a rollback when the update is rejected because of dup key?

> However, I'm not quite sure this trick completely retains the semantics of
> create_or_update, so it wouldn't be a drop-in replacement.

It would be interesting if you can make it really an atomic operation. I'm asking because
I'm not sure if transactions are enough.


> I also suspect that while savepoints may be necessary, they're not
> sufficient, and one also needs SELECT FOR UPDATE. How might I express that
> in DBIC?

An interesting question. I would be also interested in that.


Best regards
Andreas




More information about the DBIx-Class mailing list