Re: pgSet MoveNext bug ? - Mailing list pgadmin-hackers

From Dave Page
Subject Re: pgSet MoveNext bug ?
Date
Msg-id 937d27e10803050418t3e64210fq8e6544291233d4b1@mail.gmail.com
Whole thread Raw
In response to pgSet MoveNext bug ?  ("Robins Tharakan" <tharakan@gmail.com>)
List pgadmin-hackers
On Tue, Mar 4, 2008 at 1:24 AM, Robins Tharakan <tharakan@gmail.com> wrote:
> Hi,
>
> While reading the code, the PGSet->MoveNext() definition seems to have a
> small bug.
>
> Since the PGSet->EOF() is defined as
>  bool Eof() const { return (!nRows || pos > nRows); }
>
>  I think it doesn't make sense to define PGSet->MoveNext() as
> void MoveNext() { if (pos <= nRows) pos++; }
>
> It should rather be
>  void MoveNext() { if (pos < nRows) pos++; }

No - we define EOF as pos > nRows (or nRows == 0), therefore we need
to allow MoveNext() to move past the last row. This is to allow loops
like the following to work:

while (!rs.Eof())
{
    // Do stuff
    rs.MoveNext();
}

With the change you suggest, pos could never exceed nRows when changed
by MoveNext(), thus Eof() would only return true for a zero row set.

FWIW, this code has been there pretty much since v1.0.0 and we never
found ourselves losing or gaining any rows yet :-)

--
Dave Page
EnterpriseDB UK Ltd: http://www.enterprisedb.com
PostgreSQL UK 2008 Conference: http://www.postgresql.org.uk

pgadmin-hackers by date:

Previous
From: svn@pgadmin.org
Date:
Subject: SVN Commit by dpage: r7134 - branches/REL-1_8_0_EDB/pgadmin3/pgadmin/dlg
Next
From: svn@pgadmin.org
Date:
Subject: SVN Commit by dpage: r7135 - in trunk/pgadmin3: . pgadmin/db pgadmin/include/db