[CDBI] Re: atomic find_or_create()

Perrin Harkins perrin at elem.com
Mon Oct 24 17:28:39 BST 2005


On Fri, 2005-10-21 at 21:57 -0400, Edward J. Sabol wrote:
> Personally, I would just do the INSERT (using create()/insert()) and
> then check $@ for a DBMS-specific "attempt to insert duplicate key" error
> message. If that's the error, I'd search and return.

It feels kind of dirty, but I'll probably just end up doing that because
this condition is very unlikely.

> Another option is to DELETE and then INSERT, inside of a transaction.

I can't do that, or REPLACE, because I don't want to change the primary
key if it's already there.  I'm using a unique but non-primary key for
the search.

- Perrin





More information about the ClassDBI mailing list