Hi:
I see the example in the Perl DBI book dealing with setting
RaiseError OFF when connecting, then turning it ON in a block. I am trying
to do the opposite, with no success.
I connect to the database with RaiseError ON:
my $dbh = DBI->connect(undef, 'login', 'passwd', {RaiseError=>1}) or die
("Cannot connect to the database " . $DBI::errstr);
Then I have a bunch of DBI statements that I would like the program
to croak on if an error occurs:
$usg_insert = $dbh->prepare(q{
insert into usage(sid,interval,usage)
values(?, to_date(?, 'MM-DD-YYYY-HH24:MI:SS'), ?)
});
$usg_update = $dbh->prepare(q{
update usage set usage = usage + ?
where sid = ? and interval = to_date(?, 'MM-DD-YYYY-HH24:MI:SS')
});
Then I have an insert that I would like to catch the error from,
test if the insert failed for a violation of a unique constraint (duplicate
row), then try an update:
if ($usg_select->fetch()) {
$dbh->{RaiseError} = 0; # shut error catching OFF (can't get this
right)
if (!$usg_insert->execute($sid, $startTimeForOracle, $tbytes)) {
$dbh->{RaiseError} = 1; # turn error catching back on
print "INSERT OF USAGE FAILED $DBI::err $DBI::errstr\n";
if ($DBI::err == 1) {
if(!$usg_update->execute($tbytes, $sid, $startTimeForOracle)) {
print "usage update failed $DBI::err $DBI::errstr\n";
}
}
}
$dbh->{RaiseError} = 1;
}
I cannot seem to get DBI to allow me to handle the failed insert.
Any ideas or suggestions are greatly appreciated.
- Rolf.