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_sql woes
Date: Oct 25 2002 4:01PM

Guru's

I have a script as below which is failing to print the results after the
query execution. I have tried to run the query using isql and it returns the
result back fine. 

Is there anything wrong I'm doing in here?? the scalar report 0 elements in
the array and ct_callback reports no error after the query executions. All
I'm trying to do is, select the data from one database and insert it into
the other database.

Thanks for all your help in advance.

#!c:\perl/bin/perl.exe
############################################################################
#
# SCRIPT:    mt_busctr.pl
# DESCRIPTION:
#            This program gets the business counters from middletier
database
#	     and puts them in the matrics database for Sybase.
#
# AUTHOR:    Balvinder Sabherwal
# CREATED:   Oct 25, 2002
#
# 
#
# MODIFICATION HISTORY:
#
#
#
############################################################################

# import all modules
use Sybase::CTlib;

my $dbh = Sybase::CTlib->ct_connect(user, "password", SYB_DBSRVR); ##
Connect to the server.
        ct_callback(CS_SERVERMSG_CB, "srv_cb");
        ct_callback(CS_CLIENTMSG_CB, \&msg_cb);
if ($dbh){
	print "Connected to mt server\n";
}

$dbh->ct_sql("use middletierdb");

        ct_callback(CS_SERVERMSG_CB, "srv_cb");
        ct_callback(CS_CLIENTMSG_CB, \&msg_cb);
$sql = "select
MiddleTierServiceDesc+'|'+convert(varchar,convert(datetime,convert(varchar(1
2),RequestDate)))+
	
'|'+convert(varchar,datepart(hour,RequestDate))+'|'+convert(varchar,count(*)
) 
		from ServiceReqStatus a (index NClServiceReqStatus),
MiddleTierServiceType b
		where a.RequestDate between
convert(datetime,substring(getdate(),1,12)) and getdate()
		and a.MiddleTierServiceTypeCd = b.MiddleTierServiceTypeCd
		group by MiddleTierServiceDesc,
convert(datetime,convert(varchar(12),RequestDate)),
		datepart(hour,RequestDate)";

print "$sql \n";

my $DBRow = $dbh->ct_sql("$sql",undef,CS_TRUE);
        ct_callback(CS_SERVERMSG_CB, "srv_cb");
        ct_callback(CS_CLIENTMSG_CB, \&msg_cb);

print "Executed the sql \n $DBRow \n printing the rows \n";

$a = scalar @DBRow;
print "There are $a elements in array\n";
foreach $Row ( @DBRow ) {
	print "values ==>> $Row \n";
}

my $dbh = Sybase::CTlib->ct_connect(user, "password", SYB_DBSRVR); ##
Connect to the server.

if ($dbh){
	print "Connected to the matrics server \n";
	$dbh->ct_sql("use perfmondb");
}

    foreach $Row ( @DBRow ) {
	print "$Row \n";
        ($BusCtr, $SDt, $hr, $Value) = split (/\|/, $Row);
	print "$BusCtr, $SDt, $hr, $Value \n";
	$dbh->ct_sql("exec proc_busctr_data_save '$BusCtr' , '$SDT' , '$hr'
,  $Value");
    } 



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

        printf "\nOpen Client Message: (In msg_cb)\n";
        printf "Message number: LAYER = (%ld) ORIGIN = (%ld) ",
               $layer, $origin;
        printf "SEVERITY = (%ld) NUMBER = (%ld)\n",
               $severity, $number;
        printf "Message String: %s\n", $msg;
        if (defined($osmsg))
        {
            printf "Operating System Error: %s\n", $osmsg;
        }
        CS_SUCCEED;
    }


    sub srv_cb
   {
        my($dbh, $number, $severity, $state, $line, $server,
           $proc, $msg) = @_;
    # 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.

        printf "\nServer message: (In srv_cb)\n";
        printf "Message number: %ld, Severity %ld, ",
               $number, $severity;
        printf "State %ld, Line %ld\n", $state, $line;
        if (defined($server))
        {
            printf "Server '%s'\n", $server;
        }
        if (defined($proc))
        {
            printf " Procedure '%s'\n", $proc;
        }
        printf "Message String: %s\n", $msg;  CS_SUCCEED;
   }