Subject | Re: [IBO] EOF BOF craziness |
---|---|
Author | Paul Vinkenoog |
Post date | 2003-09-09T23:17:32Z |
Hi Paul,
MyDataset.First;
while not MyDataset.Eof do
begin
...
...
MyDataset.Next;
end;
IBO, also in InterBase/Firebird themselves (or SQL, for that matter),
and when reading in files. As soon as you "are" Eof, there are no
valid data to fetch.
Leaving the row pointer at the last record when reaching Eof could be
done in two ways:
1. - While stepping through records using Next, Eof is false.
- When you reach the last record, Eof is still false.
- After another Next, you stay on the last record but Eof becomes
true.
This doesn't feel right to me, because now there are two states you
can be in while at the last record: one not Eof, and one Eof.
Also, what would you do upon a Prior if Eof is true and you are on
the last record:
a) Just turn off Eof and stay on the last record? This would be
logical because it preserves Prior-Next symmetry.
b) Turn off Eof and go to the last-but-one record? Also logical,
because after all Prior means "go back one record".
2. - While stepping through records using Next, Eof is false.
- When you reach the last record, Eof is turned on.
- Subsequent Nexts do nothing.
The problem with this is that now you can't use Eof anymore in a loop
condition. Because after a First, Eof will be true both for an
empty dataset and for a dataset with one record! More general:
you'll always miss the last record of the dataset. Unless you build
in extra checks within the loop and set a flag, but that makes
things uglier than they are now.
turn on Eof as soon as you were on the last record, or as soon as you
attempted to go beyond it?
then wonder why ;-)
Greetings,
Paul Vinkenoog, shivering at 3K
>> for ( MyDataset->First(); ! MyDataset->Eof; MyDataset->Next() )The Pascal equivalent would be:
>>
>> The day Jason decides to change First and Next like you propose,
>> these loops will still compile fine but they will become black
>> holes: what goes in there never comes out again! :-)
>
> I must admit I do not understand (or want to understand ;-)) C++
> syntax...
MyDataset.First;
while not MyDataset.Eof do
begin
...
...
MyDataset.Next;
end;
> ...but I cant see why leaving the row pointer at the last recordEof usually means: immediately _past_ the end of input. Not only in
> when returning eof would make any difference.
IBO, also in InterBase/Firebird themselves (or SQL, for that matter),
and when reading in files. As soon as you "are" Eof, there are no
valid data to fetch.
Leaving the row pointer at the last record when reaching Eof could be
done in two ways:
1. - While stepping through records using Next, Eof is false.
- When you reach the last record, Eof is still false.
- After another Next, you stay on the last record but Eof becomes
true.
This doesn't feel right to me, because now there are two states you
can be in while at the last record: one not Eof, and one Eof.
Also, what would you do upon a Prior if Eof is true and you are on
the last record:
a) Just turn off Eof and stay on the last record? This would be
logical because it preserves Prior-Next symmetry.
b) Turn off Eof and go to the last-but-one record? Also logical,
because after all Prior means "go back one record".
2. - While stepping through records using Next, Eof is false.
- When you reach the last record, Eof is turned on.
- Subsequent Nexts do nothing.
The problem with this is that now you can't use Eof anymore in a loop
condition. Because after a First, Eof will be true both for an
empty dataset and for a dataset with one record! More general:
you'll always miss the last record of the dataset. Unless you build
in extra checks within the loop and set a flag, but that makes
things uglier than they are now.
> The BDE did it OK - and at least that was not the reason IT hasI've used the BDE too, long ago - did it really work that way? Did it
> ended up in a black hole :-)
turn on Eof as soon as you were on the last record, or as soon as you
attempted to go beyond it?
> > Paul Vinkenoog, beyond your wildest EOFYes, it's cold and lonely out there. This is where real men go - and
> What a frightening thought ;-/
then wonder why ;-)
Greetings,
Paul Vinkenoog, shivering at 3K