Search Postgresql Archives

Re: Suppressing Error messages.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>                                              
                      net>                           cc:                                                                                   
                           Sent by:                  Subject:   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@xxxxxxxxxxxxxxxxx




---------------------------(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
----------------------------------------------------------------------------------------------


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
       choose an index scan if your joining column's datatypes do not
       match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux