PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at bluewin dot ch>
Subject: Re: ct_callback
Date: Jul 31 2003 7:05PM

On Thu, 2003-07-31 at 19:29, Sabherwal, Balvinder (MBS) wrote:
> Guru's
> 
> I have a script which I execute and it displays all the messages on the
> screen which it should not. I have a variable which should hold the Client
> or Server error msgs via ct_callback. The connection is being established in
> a module.



> 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, ";
>     $errmsg .= "State $state, Line $line \n";
>     if (defined($server))
>     {
>         $errmsg .= "Server : $server \n";
>     }
>     if (defined($proc))
>     {
>         $errmsg .= " Procedure $proc \n";
>     }
>     $errmsg .= "Message String: $msg \n" ;  CS_SUCCEED;
>     return $errmsg;
> }

You misunderstand how the callbacks work.

The callbacks (in your case srv_cb() and msg_cb()) once they are
installed by calling ct_callback() are called by OpenClient when there
is an error, or when there is a message (such as a PRINT statement in
the SQL being executed).

The callback then does what it wants with the error and/or message
information, but it can't return that data to the main program directly.

When you call ct_callback() you *install* the callbacks (i.e. the error
handlers), you don't invoke them, so ct_callback() will definitely not
return any information related to errors or messages from the server.

Instead you need to write your callbacks so that they accumulate the
error data (which is what you've done). To return that data to the main
code you can either simply store the error data in a global variable.

Michael