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: "Sabherwal, Balvinder (MBS)" <Balvinder dot Sabherwal at mortgagefamily dot com>
Subject: ct_callback
Date: Jul 31 2003 5:29PM

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.

Can some one point out as why is this behavior?

Below is the script and module to handle the connection.

***Script***
$pwd=GetMaintPass("$opt_S", "$opt_N", "$mailto");

my $dbh=DBConnect("$opt_U", "$pwd"
,"$opt_S","testmsg.pl","$opt_N","$mailto","$pto");

$errmsg = ct_callback(CS_SERVERMSG_CB, \&srv_cb);
$errmsg .= ct_callback(CS_CLIENTMSG_CB, \&msg_cb);

if ( ! defined($dbh) )
{
   msg_send("$opt_N","testmsg.pl Script Failed","Script was not able to
connect to $opt_S server due to errors as below\n$errmsg","$mailto","$pto");
#   print "$errmsg \n";
   exit(1);
}



#### DBConnect Module########
use strict;
use Sybase::CTlib;
use DBA_Lib::SendMsg;


sub DBConnect
{
  my ($user, $pwd, $srvr, $script , $alert_type , $mailto, $pto ) = @_;
  my $dbh=undef;

  $dbh=Sybase::CTlib->ct_connect($user , $pwd , $srvr );
  
  if ( ! defined( $dbh) )
  {
      msg_send("$alert_type","$script FAILED ","$script failed while
establishing the connection to the $srvr server.","$mailto","$pto");
      $dbh=undef;
  }
  return $dbh;
}

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

    $errmsg .= "\nOpen Client Message: (In msg_cb)\n";
    $errmsg .= "Message number: LAYER = $layer ORIGIN = $origin ";
    $errmsg .= "SEVERITY = $severity NUMBER = $number \n";
    $errmsg .= "CT-Library error:\n\t $msg \n";
    if (defined($osmsg))
    {
        $errmsg .= "Operating System Error:  $osmsg \n";
    }
    CS_SUCCEED;
    return $errmsg;
}


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;
}
1;