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 MBAY dot NET>
Subject: Re: ct_res_info
Date: Nov 6 1997 10:45PM

glen@socrates.berkeley.edu wrote:
> 
> I apologize in advance for such a total newbie question.
> 
> Can anyone give me a clue (or a pointer to a sample program) about
> how to make use of ct_res_info to get the row count?  I have tried
> every variation that I can think of and all it ever returns is "0".
> 
> e.g:
> $dbh = Sybase::CTlib->ct_connect( $user, $passwd, $srvr );
> $dbh->ct_execute( $query );
> $row_count = $dbh->ct_res_info( CS_ROW_COUNT );
> print "Query returned $row_count rows \n";
> 
> produces: Query returned 0 rows
> 
> Does the call to ct_res_info have to come after ct_results?  Of
> course, I tried that with exactly the same result.

My guess is that your query is a SELECT query, and that you'd
like to know the number of rows that it returns.

Well unfortunately almost no SQL engine is capable of doing
that without processing all the rows first - the SQL engine
can't know how many rows will be returned by a particular query
without actually running the query and retrieving all the rows.

That being said, the CS_ROW_COUNT attribute is retrievable once
ct_results returns a $restype of CS_CMD_DONE, so you should
write a loop to get the number of rows affected, like this:

$dbh->ct_execute($query);
while($dbh->ct_results($restype) == CS_SUCCEED) {
    if($restype == CS_CMD_DONE) {
       $numrows = $dbh->ct_res_info(CS_ROW_COUNT);
    }
    # do any other processing here
    # for example, process any fetchable rows:
    if($dbh->ct_fetchable($restype)) {
       while(@dat = $dbh->ct_fetch) {
          # do whatever you need to do with the data...
       }
     }
}


Hope this helps a little bit...

Michael
-- 
Michael Peppler       -||-  Data Migrations Inc.
mpeppler@datamig.com  -||-  http://www.mbay.net/~mpeppler