Search code examples
perlsybase

Sybase Warning messages from perl DBI


I am connecting to sybase 12 from a perl script and calling storedprocs, I get the following warnings

DBD::Sybase::db prepare failed: Server message number=2401 severity=11 state=2 line=0 server=SERVER_NAME text=Character
set conversion is not available between client character set 'utf8' and server character set 'iso_1'.
Server message number=2411 severity=10 state=1 line=0 server=SERVER_NAME text=No conversions will be done.
at line 210.

Now, I understand these are only warnings, and my process works perfectly fine, but I am calling my stored proc in a loop and throughout the day and hence it creates a lot of warning message in my log files which causes the entire process to run a bit slower than expected. Can someone help me how can i suppress these please?


Solution

  • You can use a callback to handle the messages you want ignored. See the DBD::Sybase docs. The below is derived from the docs. You specify the message numbers you would like to ignore.

    %blocked_msgs = map { $_ => 1 }  ( 2401, 2411 );
    sub err_handler {
      my($err, $sev, $state, $line, $server, $proc, $msg, $sql, $err_type) = @_;
    
       if ( exists $blocked_msgs{$err} ) { # it's a blocked message
         return 0;    # This is not an error
       }
       return 1;
    }
    

    This is how you might use it:

    $dbh = DBI->connect('dbi:Sybase:server=troll', 'sa', '');
    $dbh->{syb_err_handler} = \&err_handler;
    $dbh->do("exec someproc");
    $dbh->disconnect;