Skip to content

Instantly share code, notes, and snippets.

@alexdioso
Created September 18, 2011 19:51
Show Gist options
  • Save alexdioso/1225479 to your computer and use it in GitHub Desktop.
Save alexdioso/1225479 to your computer and use it in GitHub Desktop.
Perl DBI HandleError
my $dbh = DBI->connect(
'dbi:Pg:dbname=DATABASE_NAME',
q{},
q{},
{
RaiseError => 1,
AutoCommit => 0,
PrintError => 0,
ShowErrorStatement => 1,
HandleError => sub {
my $errormsg = shift;
my $handle = shift;
my $dbh;
my $type = $handle->{'Type'};
if ($type eq 'st') {
$dbh = $handle->{'Database'};
} elsif ($type eq 'db') {
$dbh = $handle;
} else {
warn "Unknown handle type: $type";
confess $errormsg;
}
$dbh->rollback;
confess $errormsg;
}
}
);
# No check needed
$sth->execute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment