SunQuest
           Firebird SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesFirebird SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old June 27th, 2003, 02:39 AM
btauler btauler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Catalonia - Spain
Posts: 6 btauler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Knowing Number of registers from a Select

Is there any way to know the number of registers that will come out from a given select?

I'm using PHP and PEAR abstraction layer with Firebird 1.0.3, and I tried query->numRows() but i got a message telling me that "db is not capable". Is that true that interbase is not capable?

TIA,

Ben

Reply With Quote
  #2  
Old June 27th, 2003, 03:16 AM
jpenn's Avatar
jpenn jpenn is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2002
Location: Washington, DC
Posts: 2,693 jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 41 m 10 sec
Reputation Power: 16
Lol - its more than capable. Send a standard query and use COUNT() to get your number of rows:
Code:
SELECT COUNT(*) FROM TABLE WHERE SOMETHING = SOMETHING

SOMETHING = SOMETHING would be some condition...
__________________
~ Joe Penn

Reply With Quote
  #3  
Old June 27th, 2003, 03:52 AM
btauler btauler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Catalonia - Spain
Posts: 6 btauler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Any other way?

That requires two selects, one to know number of reg's, and another to get the result set, knowing that my select takes a large amount of time that wouldnt be an option.

Yours,

Ben

Reply With Quote
  #4  
Old June 27th, 2003, 06:55 AM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
It's not a problem with firebird, rather a limitation of the php api. The IB api for php seems a bit immature compared to those for other RDBMS.

I would suggest storing the result set to an array and counting the array.
__________________
FSBO (For Sale By Owner) Realty

Reply With Quote
  #5  
Old June 27th, 2003, 09:06 AM
btauler btauler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Catalonia - Spain
Posts: 6 btauler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok, so there is no way to know it directly from the api. But, is it possible from let's say DB Express components... , or even, is firebird capable of knowing the number of reg's from a select without having feched all of them (and without doing count(*)).

Thank you all.


Reply With Quote
  #6  
Old June 27th, 2003, 05:43 PM
Set Set is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: Oslo, Norway
Posts: 11 Set User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
"No way" is a very dangerous answer to give, but it is temping. How could it know without counting them, taking into account that the correct answer could depend upon which transaction it was executed within?

Generally, doing a SELECT COUNT is an expensive operation in a client/server database, and may in many cases indicate that the person wanting to count rows (at least if we're talking about a number higher than the number of rows that fit onto the screen) still thinks in terms of desktop databases.

My advice is to limit your counting to situations were they are really needed (a progress bar is not such a situation) or for doing the count during or after the retrieval (I don't know PHP, but IBO does have a property named ReturnedRows or something).

Reply With Quote
  #7  
Old June 27th, 2003, 07:23 PM
jpenn's Avatar
jpenn jpenn is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jun 2002
Location: Washington, DC
Posts: 2,693 jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level)jpenn User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 41 m 10 sec
Reputation Power: 16
Unfortainatly, as Rod pointed out - the php/ibase api is missing quite a few of the handy functions found in php/pg and php/mysql. What do you need a count for? I see alot of people getting row counts and using them in conditionals:
Code:
if ( mysql_num_rows( $query ) > 0 )
{
      /* Do Something */
}

Is this what you are looking for - to see if 1 or more rows were returned?

If so, this can be accomplished like this in fb/php:
Code:
$query = ibase_query( /* The Query String */ );
/*----------------------------------------------
Check To See If Scalar Is Resource
----------------------------------------------*/
if ( is_resource( $query ) )
{
      /* Evaluates to true if 1 or more rows were returned */
}
else
{
      /* Will eval to false if query failed or 0 rows were returned */
}

It should be the same when using the pear methods also...

Reply With Quote
  #8  
Old July 7th, 2003, 05:08 AM
btauler btauler is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Catalonia - Spain
Posts: 6 btauler User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I need to exactly know the number of returned rows, I want to put a muli page list of records. So i need to know the number of rows to generate links at bottom of the page to navigate between the pages.

And yes, select count(*) is too expensive in time to use it.

I guess I'll have to wait for maintainer to implement returnedRows functionality on ibase api.

Thank you again,
BEN

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesFirebird SQL Development > Knowing Number of registers from a Select


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

IBM developerWorks




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway