Re: Suppressing Error messages. - Mailing list pgsql-general

From SCassidy@overlandstorage.com
Subject Re: Suppressing Error messages.
Date
Msg-id OFE6A66F1A.79438D75-ON88257058.0074EFAD-88257058.007658E5@myoverland.net
Whole thread Raw
In response to Suppressing Error messages.  ("Basith Salman" <bsalman@lemurnetworks.net>)
List 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@lemurnetworks.        To:       <pgsql-general@postgresql.org>
                   
                      net>                           cc:
                   
                           Sent by:                  Subject:  [GENERAL] Suppressing Error messages.
                   

                   
                                                      |-------------------|
                   
                      pgsql-general-owner@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@lemurnetworks.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
----------------------------------------------------------------------------------------------


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: best way to reference tables
Next
From: CSN
Date:
Subject: NOTIFY/LISTEN, PHP, rule vs. trigger, blocking, missed NOTIFY's