From: | Aditya <aditya(at)grot(dot)org> |
---|---|
To: | sfpug(at)postgresql(dot)org |
Subject: | Re: DBD::pg error trapping? |
Date: | 2003-02-26 19:58:36 |
Message-ID: | 20030226195836.GA94998@mighty.grot.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | sfpug |
On Wed, Feb 26, 2003 at 11:38:48AM -0800, Josh Berkus wrote:
> I know we have a few perl hackers on this list. Can anyone give me a simple
> example of trapping error output from DBD::pg when a query fails? I can't
> seem to get it to work right ... the errors end up being fatal to the Perl
> program.
my($dbh) = DBI->connect($data_source, $user, $dbpassword,
{RaiseError => 0} #depends on whether you check errstr
) || die "couldn't call $data_source: $DBI::errstr\n";
$dbh->{ChopBlanks} = 1;
$dbh->{AutoCommit} = 1;
$dbh->{RaiseError} = 0;
$dbh->{PrintError} = 0;
my $query = <<SQL;
select foo from bar
SQL
my($sth) = $dbh->prepare($query);
if ($dbh->err()){
notify('crit', "ERROR: ($query) " . $dbh->errstr);
}
my($rv) = $sth->execute();
if ($sth->err()){
notify('crit', "ERROR: ($query) " . $sth->errstr);
}
#notify is a small internal subroutine that sends stuff to syslog etc
From | Date | Subject | |
---|---|---|---|
Next Message | David Fetter | 2003-02-26 20:01:20 | Re: DBD::pg error trapping? |
Previous Message | Josh Berkus | 2003-02-26 19:50:17 | Re: DBD::pg error trapping? |