Thread: pgSet MoveNext bug ?
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++; }
The attached patch does the same.
Regards,
Robins Tharakan
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++; }
The attached patch does the same.
Regards,
Robins Tharakan
Attachment
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