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

Ash Berlin ash_cpan at firemirror.com
Tue Jul 29 11:58:26 BST 2008


On 29 Jul 2008, at 11:49, Tobias Kremer wrote:

> 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?
>
> --Tobias

Maybe this was mentioned in earlier in the thread, (or perhaps this is  
the problem in the first place?), but DBIx::Class does have a  
find_or_create method.

Can that not be used?

-ash



More information about the Catalyst mailing list