perl5ever has asked for the wisdom of the Perl Monks concerning the following question:
$run is a DBIx::Class result object created using ->new. The purpose of this is to atomically test to see if the primary key for $run already exists in the database and insert the row if it doesn't. Otherwise it returns false.sub insert_run { my $self = shift; my $run = shift; eval { $run->insert; }; if ($@) { if ($@ =~ m/ORA-00001: unique constraint/) { return 0; } die $@; } return 1; }
Is there a database independent way to do this?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to tell if ->insert succeeded in DBIx::Class?
by ikegami (Patriarch) on Feb 22, 2011 at 23:16 UTC | |
|
Re: how to tell if ->insert succeeded in DBIx::Class?
by 7stud (Deacon) on Feb 22, 2011 at 23:16 UTC | |
by perl5ever (Pilgrim) on Feb 22, 2011 at 23:40 UTC | |
by ikegami (Patriarch) on Feb 22, 2011 at 23:26 UTC |