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: RE: ct-lib error in the perl script
Date: Jan 2 2002 7:11PM

This is printing the column headers above every data row. How can I change
this to print the column header only once and then print all the data rows??

-----Original Message-----
From: Michael Peppler [mailto:mpeppler@peppler.org]
Sent: Wednesday, January 02, 2002 12:30 PM
To: SybPerl Discussion List
Subject: RE: ct-lib error in the perl script


You can use this:

my $data = $dbhndl->ct_sql("exec sp_who", undef, CS_TRUE);

foreach my $row (@$data) {
    my @cols = keys(%$row);
    print "@cols\n";
    foreach (@cols) {
        print "$row->{$_} ";
    }
    print "\n";
}


Michael


Sabherwal, Balvinder (MBS) writes:
 > Is there a way to get the column headings??
 > 
 > my $data = $dbhndl->ct_sql("exec sp_who");
 > 
 > foreach my $row (@$data) {
 >     foreach my $col (@$row) {
 >         print "$col ";
 >     }
 >     print "\n";
 > }
 > 
 > The code above prints only the data and not the column headings.
 > 
 > Thanks
 > Bal.
 > 
 > -----Original Message-----
 > From: Michael Peppler [mailto:mpeppler@peppler.org]
 > Sent: Monday, December 17, 2001 4:05 PM
 > To: SybPerl Discussion List
 > Subject: Re: ct-lib error in the perl script
 > 
 > 
 > Sabherwal, Balvinder (MBS) writes:
 >  > I am getting the error as below :
 >  > 
 >  > Open Client Message:
 >  > Message number: LAYER = (1) ORIGIN = (1) SEVERITY = (1) NUMBER = (155)
 >  > Message String: ct_results(): user api layer: external error: This
 > routine
 >  > cannot be called when the command structure i
 >  > s idle.
 > 
 > 
 > 
 >  >       $dbhndl->ct_sql("exec sp_who");
 > 
 >  >     while(($rc = $dbhndl->ct_results($restype)) == CS_SUCCEED) 
 >  >     {
 > 
 > You have a fundamental misunderstanding of what ct_sql() does.
 > 
 > If you replace ct_sql("exec sp_who") with ct_execute("exec sp_who")
 > you'll get the results you expect.
 > 
 > But you can also use ct_sql() directly - ct_sql() executes the query
 > for you, and packages all the results in an array:
 > 
 > my $data = $dbhndl->ct_sql("exec sp_who");
 > # now $data is a reference to an array, where each element of the
 > # array is one row returned by the query you executed:
 > foreach my $row (@$data) {
 >     foreach my $col (@$row) {
 >         print "$col ";
 >     }
 >     print "\n";
 > }
 > 
 > Of course you probably want to do something a little fancier with the
 > data - the loop above is just to give you an idea...
 > 
 > Michael
 > -- 
 > Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
 > mpeppler@peppler.org - mpeppler@mbay.net
 > International Sybase User Group - http://www.isug.com
 > 

-- 
Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
mpeppler@peppler.org - mpeppler@mbay.net
International Sybase User Group - http://www.isug.com