• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

lenght() or row count?

 
Timy McTipperstan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm executing a query against my database for a certain type of result. SO not all rows will return, which is expected. How ever I am having an issue in getting the row count or length of the result.

I dont really want to run another query to get the number cant I run .lenght on the result and get the interger?
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

The problem is really that there isn't any interaction with the databse until you do something with the result set.

You have 3 options:

(1) As you say, do a 'select count(*)' or 'count( whatever your query is )'
(2) Iterate through your resultset keeping a tally
(3) If you are able to use scrollable resultsets, take a look at this approach.
[ March 15, 2005: Message edited by: Horatio Westock ]
 
Timy McTipperstan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#3 looks like a better option for what I want to do.
thanks
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before you decide for sure, take a look at the final section of this article.

You should check that your DB and driver definitely support scrollable cursors, and don't just emulate it. If not, you are basically going to be getting every row anyway.
 
Carol Enderlin
drifter
Ranch Hand
Posts: 1364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this isn't as easy as it seems like it might be it is worth asking, why do you need to know how many rows have been returned?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JDBC...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic