Solved

Sybase returning row numbers

Posted on 2001-07-08
6
2,951 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
  • 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now