Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: DBI, sp_rename, and STDERR

by mda2 (Hermit)
on Jul 20, 2005 at 14:42 UTC ( #476511=note: print w/replies, xml ) Need Help??

in reply to DBI, sp_rename, and STDERR

Check your connect.

PrintError parameter is default on DBI.

$dbh = DBI->connect($DSN, $USER, $PASS, { PrintError => 0 } );

Marco Antonio

Replies are listed 'Best First'.
Re^2: DBI, sp_rename, and STDERR
by derby (Abbot) on Jul 20, 2005 at 14:52 UTC

    That's not going to work. Setting PrintError to 0 just prevents perl from calling warn when errors are encountered. This isn't an error but a print statement in the sp_rename proc. Normally I handle this by nicely asking the stored proc dev to remove the offending print statement - something your DBA might frown upon when dealing with a system proc!

    Update: Kudos to Jason for the correct answer.


      This is a perfectly acceptable method unless we call system stored procedures (i.e. sp_rename) or where the source of the stored procedure is not available (3rd party). In truth, only using an error handler will 'catch' the print statement output from being sent to STDERR.

      Jason L. Froebe

      Team Sybase member

      No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

        Have you tried it? I've never been able to catch print statements from stored procs with an error handler ( DBD::Sybase Version 1.61 and Sybase 12.5.x).

        I tried using your error handler on a tempdb table I created

        !/usr/local/bin/perl use strict; use DBI; my $dbh = DBI->connect("dbi:Sybase:server=xxx", "u", "p", { PrintError => 0, syb_err_handler => \&syb_error_handler } ); $dbh->do( "use tempdb" ); my $sql = "exec sp_rename derby, derby1"; $dbh->do( $sql ); sub syb_err_handler { my ($err, $sev, $state, $line, $server, $proc, $msg, $sql, $err_ty +pe) = @_; my $ERROR = 1; my $WARNING = 0; my $return_code = $ERROR; if ( ($err == 131) && ($sev == 5) ) { ## Connection attempt failed return $ERROR; } elsif ( ($err == 0) && ($sev == 10) && ($state == 1) ) { if ( $msg =~ m/Active traceflags:/i ) { process_dbcc_list($msg); $return_code = $WARNING; } else { unless ( $msg =~ m/^\s+$/ ) { chomp $msg; print $msg . "\n"; } } $return_code = $WARNING; } elsif ( ($err == 3) && ($sev == 5) ) { print "err: $msg\n"; $return_code = $ERROR; } return ($return_code); }

        Just didn't work. The print statement was not caught by the error handler and was outputted to STDERR.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://476511]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2019-12-14 17:53 GMT
Find Nodes?
    Voting Booth?

    No recent polls found