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

Matt S Trout dbix-class at trout.me.uk
Wed Jul 30 11:26:28 BST 2008

On Tue, Jul 29, 2008 at 12:49:17PM +0200, 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 :(

It's still probably viable.

What I'd really like is to add some code to DBIC's storage to know what re
that /duplicate/ is on whatever DB so we can bury this away from the user
and DBIC can Just Use It for find_or_create on any supported database.

Maybe you could wander over to the DBIC list and poke at patching that

      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

More information about the Catalyst mailing list