Re: CDatabase CRecordset - How to get the number of rows?
- From: "Roy Fine" <rlfine@xxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Jun 2005 22:25:04 -0400
"David++" <David@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:780B7B8F-52A2-4775-8697-2D33A5A8C0C7@xxxxxxxxxxxxxxxx
> Hi,
>
> Thanks for both your answers. I've changed my code a bit to this -
>
> CRecordset rs(&db);
> rs.Open(CRecordset::forwardOnly,_T( "SELECT * FROM Records" ) );
>
> int count = 0;
> while (!rs.IsEOF())
> {
> count += 1;
> rs.MoveNext();
> }
>
> I've now dropped the COUNT (*) and have used just * in the SQL Statement.
It
> seems to be working a little better but i cant fully check it as I'm on my
> home computer now. Interestingly, if I use the MoveLast() function I get a
> runtime Debug Assertion failure?
>
> Well, thanks once again for your help and views. I'll post any outcomes I
> make,
>
> Best,
> David
What you have is most inefficient method available for determining the
number of rows in a cursor - by fetching each row, and incrementing a
counter. Consider the impact of moving the database to a host on the
network (ever better, to a host on an internet). In this case, network
delays kill performance.
Consider something like this (which pushes most of the work to the database
server and fetches one row with one field):
CRecordset rs(&db);
rs.Open(CRecordset::ForwardOnly,"Select count(*) from
Records",CRecordset::ReadOnly);
CDBVariant vtval;
rs.GetFieldValue((short)0,vtval);
int rowcount = vtval.m_lVal;
rs.Close();
regards
Roy Fine
.
- Follow-Ups:
- References:
- Prev by Date: Re: CString -> char (easy question)
- Next by Date: Re: CString -> char (easy question)
- Previous by thread: Re: CDatabase CRecordset - How to get the number of rows?
- Next by thread: Re: CDatabase CRecordset - How to get the number of rows?
- Index(es):
Relevant Pages
|
Loading