|
|
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 4:51PM
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
|