Solved

Sybase returning row numbers

Posted on 2001-07-08
6
2,999 Views
Last Modified: 2007-11-27
How can I get sybperl to give me the row count after executing an SQL Query (a "SELECT" query, for example).

If I query a database with ct_execute, I then call:

$count = $dbh -> ct_res_info(CS_NUMDATA)

...but $count seems to give me completely arbitrary values (i.e.: 15 for 10 rows, 58 for 713 rows, 180
for no results, etc..)

Am I missing something here?
0
Comment
Question by:Tonyboy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 5

Expert Comment

by:amitpagarwal
ID: 6263674
Well - it would: that's the number of columns in the result set, not the number of rows. Use CS_ROW_COUNT instead.


 $rows = $dbh->ct_res_info(CS_ROW_COUNT);
0
 

Author Comment

by:Tonyboy
ID: 6265650
Hmmm... I agree with your solution, but given the following Perl script (I hope you're familiar):

if ($restype == CS_ROW_RESULT) {
     $sql_rows = $dbh -> ct_res_info(CS_ROW_COUNT) || 1;
}

For some reason, though, CS_ROW_COUNT never returns any value, and so the 1 is used (if I put 2 there, the 2 would be used, etc...)
0
 
LVL 5

Accepted Solution

by:
amitpagarwal earned 200 total points
ID: 6265688
It's a protocol thing... Sybase doesn't know (or doesn't tell the APIs) how many rows are returned until all the rows have been fetched,   so you can't know in advance how many rows will be returned by a query    unless you do a select count(*) first.

 The CS_ROW_COUNT property is really usefull for updates/inserts/deletes,   though...

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...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:Tonyboy
ID: 6265748
Oh... That's dissapointing..

Is there any way of finding out how many rows are returned before fetching all of the results?
0
 
LVL 5

Expert Comment

by:amitpagarwal
ID: 6265754
listening ..
0
 

Author Comment

by:Tonyboy
ID: 6265798
???
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ODBC connection for Raiser's Edge 6 --SqlAnywher 5.0 8 817
Sybase - sp_cacheconfig 1 1,046
SyBase SQL DataTime Format 6 300
Call sybase stored procedure from php 8 93
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
Check out this step-by-step guide for asking an anonymous question on Experts Exchange.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question