Re: Suppressing Error messages.

From: SCassidy(at)overlandstorage(dot)com
To: bsalman(at)lemurnetworks(dot)net, pgsql-general(at)postgresql(dot)org
Subject: Re: Suppressing Error messages.
Date: 2005-08-09 21:32:40
Message-ID: OFE6A66F1A.79438D75-ON88257058.0074EFAD-88257058.007658E5@myoverland.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Hi,

To get rid of the automatic output, turn PrintError off.

For example:

$dbh = DBI->connect("dbi:Pg:dbname=$dbname;host=${dbserver};", $dbuser,
"",{PrintError => 0}) or
errexit( "Unable to connect to dbname $dbname, err: $DBI::errstr");

See the "perldoc DBI" documentation for full information. Here is part of
it:

"PrintError" (boolean, inherited)
The "PrintError" attribute can be used to force errors to
generate
warnings (using "warn") in addition to returning error codes in
the
normal way. When set "on", any method which results in an error
occuring will cause the DBI to effectively do a "warn("$class
$method failed: $DBI::errstr")" where $class is the driver class
and $method is the name of the method which failed. E.g.,

DBD::Oracle::db prepare failed: ... error text here ...

By default, "DBI->connect" sets "PrintError" "on".

If desired, the warnings can be caught and processed using a
$SIG{__WARN__} handler or modules like CGI::Carp and CGI::Error-
Wrap.

Normally, I catch errors myself in web applications, and output to a log
and/or the screen appropriately. For this, you may want to turn off
RaiseError, also. For example, you can look for a specific error message,
and do special things under certain circumstances:

my $rc2=$sth2->execute($val1, $val2);
if (!$rc2) {
#will be undef if a problem occurred
if ($DBI::errstr=~/$dupKeyString/) { #$dupKeyString is
set to the actual string we expect
# This is expected sometimes
LogMsg("Duplicate key on val \"$val1\"");
} else {
my $msg2="Unexpected error during insert of val \"$val\": DB
error: $DBI::errstr";
db_error_exit ($msg2);
}
}

This is just some quick example code, but you get the idea.

Hope this helps,
Susan


"Basith Salman"
<bsalman(at)lemurnetworks(dot) To: <pgsql-general(at)postgresql(dot)org>
net> cc:
Sent by: Subject: [GENERAL] Suppressing Error messages.

|-------------------|
pgsql-general-owner(at)pos | [ ] Expand Groups |
tgresql.org |-------------------|


08/05/2005 07:42
AM
Please respond to
bsalman

Hi All,

I was wondering if there is way to suppress the error messages on the
stdout

from a perl dbi execute command, basically if I do a

sth->execute() on a command and say the row cannot be updated then

I get a err msg to stdout if there is foreign key violation, I want this
error message

to be directed to a log file.

Is this possible.

TIA.

bsalman(at)lemurnetworks(dot)com

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org

----------------------------------------------------------------------------------------------
See our award-winning line of tape and disk-based
backup & recovery solutions at http://www.overlandstorage.com
----------------------------------------------------------------------------------------------

Browse pgsql-general by date

  From Date Subject
Next Message CSN 2005-08-10 00:52:52 NOTIFY/LISTEN, PHP, rule vs. trigger, blocking, missed NOTIFY's
Previous Message Tom Lane 2005-08-09 20:37:56 Re: best way to reference tables