Take a look at the Error module (although you can use eval as well).

use DBI;
use Error qw(:try);

my $dbh = DBI->connect(...);
$dbh->{RaiseError} = 1;

try {
  $dbh->do("insert ...");
}
catch Error with {
  print STDERR "Insert failed!";
}

$dbh->do("update ...");


...Or if you only want to update when the insert fails, then put the insert
in the catch block.

Rob


-----Original Message-----
From: Titu Kim [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 27, 2003 2:37 PM
To: [EMAIL PROTECTED]
Subject: How to cate DBI error and pass the control to subroutine?


Hi, 
   I am using DBI and DBD to insert into database. If
the insert fails because of the key constraints, I
want to continue to update that record. How can I it
do this after I issue $sth->execute() statement?


Thanks.

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to