[Catalyst] Duplicate entries with C::P::Session::Store::DBIC and MySQL

Tobias Kremer list at funkreich.de
Tue Jul 29 11:49:17 BST 2008

Quoting Tobias Kremer <list at funkreich.de>:
> However, I'm unsure how to detect if the error really was a duplicate entry
> error or something else.
>   die $@ if $@ && $@ !~ /duplicate/i;
> This doesn't work because different DBs throw different errors.

Also, flash() is supposed to always return a flash entry. So in case of a
duplicate error we'd have to do another find(). That'd be 3 queries in the
worst case.

Maybe it'd be better to ditch find_or_create in favor of something like this:

eval {
  $row = $self->model->create( { ... } );
if( $@ && $@ =~ /duplicate/ ) { # the question about detecting this remains
  $row = $self->model->find( { ... } );

This would reduce the query to 1 at best and 2 at worst. On the other hand, I
fear that it's still possible that the find() doesn't actually find a row
because it was deleted in the meantime by the other request :(

Any ideas?


More information about the Catalyst mailing list