RE: Question on proc execution with sybperl

Michael Peppler <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.sybase
Message-ID <[email protected]>
On Fri, 2004-09-24 at 19:36, Sabherwal, Balvinder (MBS) wrote:
> Here are the callback routines that I'm using. I'm ignoring all the msgs.
> Where severity is <= 10 in it. The proc's are not printing any messages that
> are being set in the $errmsg. I think it's the server that is echoing back
> the proc execution. If I comment out the callback line for the server
> messages, it works fine. The problem with that is if there are any errors,
> I'll not be able to check that.

Actually you need to check the logic of your srv_cb code...

> sub srv_cb
> {
>     my($dbh, $number, $severity, $state, $line, $server, $proc, $msg) = @_;
> #    my $errmsg;
>     # If $dbh is defined, then you can set or check attributes
>     # in the callback, which can be tested in the main body
>     # of the code.
> 
> #    $errmsg .= "\nServer message: (In srv_cb)\n";
>     $errmsg .= "Message_number $number, Severity $severity, " if ( $severity
> gt "10" );
>     $errmsg .= "State $state, Line $line \n" if ( $severity gt "10" );
>     if (defined($server))
>     {
>         $errmsg .= "Server : $server \n" if ( $severity gt "10" );
>     }

Here's the problem - if $proc is defined, you set $errmsg
unconditionally, with no test for the severity level.

>     if (defined($proc))
>     {
>         $errmsg .= " Procedure $proc \n";
>     }
>     $errmsg .= "Message String: $msg \n" if ( $severity gt "10" ) ;
> CS_SUCCEED;
> }

Personally I'd change the logic around. As you only care about messages
if the $severity is > 10, I'd do:

sub srv_cb {
   my($layer, $origin, $severity, $number, $msg, $osmsg, $dbh) = @_;

   # Shortcut logic - if it's a low severity then just return.
   return CS_SUCCEED unless $severity > 10;

   # Add logic to build the $errstr here...

   $errmsg .= "Message_number $number, Severity $severity, ";
   .....

   return CS_SUCCEED;
}


This will make the logic of your callback a lot simpler.

Michael


> 
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On
> Behalf Of Michael Peppler
> Sent: Friday, September 24, 2004 1:39 AM
> To: '[email protected]'
> Subject: Re: Question on proc execution with sybperl
> 
> On Thu, 2004-09-23 at 21:57, Sabherwal, Balvinder (MBS) wrote:
> 
> > I have a script that is executing a proc on Sybase 12.5.0.3 ASE with
> > the below code. 
> 
> > $dbhS->ct_sql("exec $opt_D..proc_arch_mt $glun");  ## Archive this
> > GLUN
> > 
> >    if ( defined($errmsg) )         ## Make sure there were no errors
> > in the last sql execution.
> >    {
> >       msg_send("$opt_N","MT_Arch.pl Failed for $opt_D on $opt_S " ,
> > "Script failed due the errors below.\n$errmsg\n","$mailto","$pto");
> >       exit(1);
> >    }
> 
> > Upon execution, It fails with the error message as below. Can some one
> > point me to the solution so I do not get this message back?
> 
> >          Script failed due the errors below.
> > 
> >  Procedure proc_arch_mt 
> 
> There's not enough in the code snippet above to determine why $errmsg
> gets set.
> 
> My guess is that you need to define a server callback or change the one
> you already have to ignore certain types of messages from the proc.
> 
> Michael
-- 
Michael Peppler                              Data Migrations, Inc.
[email protected]                       http://www.peppler.org/
Sybase T-SQL/OpenClient/OpenServer/C/Perl developer available for short or 
long term contract positions - http://www.peppler.org/resume.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.