From: | "Dave Page" <dpage(at)pgadmin(dot)org> |
---|---|
To: | "Robins Tharakan" <tharakan(at)gmail(dot)com> |
Cc: | pgadmin-hackers(at)postgresql(dot)org |
Subject: | Re: pgSet MoveNext bug ? |
Date: | 2008-03-05 12:18:15 |
Message-ID: | 937d27e10803050418t3e64210fq8e6544291233d4b1@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgadmin-hackers |
On Tue, Mar 4, 2008 at 1:24 AM, Robins Tharakan <tharakan(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | svn | 2008-03-05 12:51:21 | SVN Commit by dpage: r7135 - in trunk/pgadmin3: . pgadmin/db pgadmin/include/db |
Previous Message | svn | 2008-03-05 11:47:57 | SVN Commit by dpage: r7134 - branches/REL-1_8_0_EDB/pgadmin3/pgadmin/dlg |