Re: CDatabase CRecordset - How to get the number of rows?




"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


.



Relevant Pages

  • Re: [PATCH] [MMC] Lindent wbsd driver
    ... Basic functions */ -static inline void wbsd_unlock_config(struct wbsd_host* host) +static inline void wbsd_unlock_config{ ... * Common routines */ -static void wbsd_init_device+static void wbsd_init_device{u8 setup, ... } -static inline int wbsd_next_sg+static inline int wbsd_next_sg{/* ...
    (Linux-Kernel)
  • [git pull] IDE updates part 2
    ... More IDE changes for 2.6.31 merge window: ... pdc202xx_old host driver fixes. ... int ret; ... struct ide_host *host; ...
    (Linux-Kernel)
  • [EXPL] Squid Buffer Overflow Exploit Code Released (FTP)
    ... you can change the host who runs ftp server but in this way ... void shell(int fd) ... unsigned long resolve(char * host) ... memset(pad, 0x7e, sizeof(pad)); ...
    (Securiteam)
  • Re: Two 3825s wont talk to each other
    ... DDR TXCRC Int Mask 1 DDR TXClk Loss Int Mask 1 ... Network Interrupt Enable: ... Last clearing of "show interface" counters never ... input packets with dribble condition detected ...
    (comp.dcom.sys.cisco)
  • [PATCH 6/7] ide: pass number of ports to ide_host_{alloc,add}()
    ... struct ide_host *host; ... int ret = 0; ...
    (Linux-Kernel)

Loading