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 peppler dot org>
Subject: Re: client api layer error
Date: Jun 6 2001 5:47PM

Patrick S. Leung writes:
 > Thanks Michael,
 > 
 > The exact same perl scripts works with any other sybase (on linux) db I 
 > have except for one particular sybase ase on linux.  I understand what 
 > you said about the fetch data, and for the sake of completness, here the 
 > entire code fragment:
 > 
 > $query="SELECT id FROM table_one";
 > 
 > $X->ct_execute($query);
 >  
 > while(($rc = $X->ct_results($restype)) == CS_SUCCEED) {
 >         next if($restype == CS_CMD_DONE || $restype == CS_CMD_FAIL ||
 >                 $restype == CS_CMD_SUCCEED);
 >         while(@dat = $X->ct_fetch) {

I suspect that your bug is here:

 >                         if($dat[0] eq "") {
 >                                 last;
 >                         }

If $dat[0] is null or an empty string, then you exit the loop one
iteration early and this causes the internal logic of OpenClient to
break.

The while() loop will exit automatically when the last row has been
fetched, so if you want to skip rows where $dat[0] is empty you should
replace the "last" with a "next", and your code should work fine.

Also - you should use ct_fetchable() to check for fetchable results as
that is (possibly) more complete.

Michael

 > Michael Peppler wrote:
 > 
 > >Patrick S Leung writes:
 > > > Dear all,
 > > > 
 > > > I use a perl script to fetch data from sever sybase ase dbs.  The perl 
 > > > scripts are on one linux machine while the db is on another linux 
 > > > machine.  All but one sybase server gave me the open client error.  I 
 > > > got the error even if I run the perl script on the same machine. 
 > > > 
 > > > Open Client Message:
 > > > Message number:  LAYER = (1) ORIGIN = (1)  SEVERITY = (1) NUMBER = (163)
 > > > Message String:  ct_results():  user api layer: external error:  This 
 > > > routine cannot be called until all fetachable results have been 
 > > > completely processed.
 > >
 > >Your perl code is almost certainly incorrect. You *must* call
 > >ct_fetch() within the ct_results() loop for *all* result types that
 > >return rows, even if there are no rows in that result set.
 > >
 > >Specifically you need to do something like this (semi-pseudocode):
 > >
 > >ct_execute(...);
 > >while(ct_results($restype) == CS_SUCCEED) {
 > >    next unless ct_fetchable($restype);
 > >    while(@d = ct_fetch) {
 > >        ....
 > >    }
 > >}
 > >
 > >If you don't want to have to mess with all that I strongly suggest you
 > >take a look at Sybase::Simple, where you have methods that will hide
 > >all this complexity from you.
 > >
 > >Michael
 > >
 > 
 > 

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