Discussion:
Last record not being processed
(too old to reply)
Ney André de Mello Zunino
2006-07-18 00:38:33 UTC
Permalink
Hello.

I have a very basic loop over a query object (TADOQuery) which is not
behaving as expected. It is contained in a member function which is
supposed to check whether any of the records contain a non-zero value in
a given column ("correlation"):

bool TdmMonteCarlo::checkCorrelation() const
{
aqOperations->DisableControls();
bool correlation = false;
int idCurrent = aqOperations->FieldByName("id")->AsInteger;

aqOperations->First();
while (!aqOperations->Eof)
{
if (aqOperations->FieldByName("correlation")->AsFloat != 0.0)
{
correlation = true;
break;
}
aqOperations->Next();
}

aqOperations->Locate("id",
AnsiString(idCurrent).c_str(),
TLocateOptions());
aqOperations->EnableControls();
return correlation;
}

The problem is that the last record is not being processed. In other
words, the /Eof/ property is becoming true just as the cursor moves to
the last record, not when it tries to go beyond it, as things normally
work. Does anybody have any idea of what could be causing this? I read
somewhere else that Eof might behave strangely when key fields are
modified, but the loop in question is a read-only one.

Thank you for any feedback.
--
Ney André de Mello Zunino
Mark Guerrieri
2006-07-19 15:45:02 UTC
Permalink
What version are you using?

Do you have any filters in place?

Mark
Post by Ney André de Mello Zunino
Hello.
I have a very basic loop over a query object (TADOQuery) which is not
behaving as expected. It is contained in a member function which is
supposed to check whether any of the records contain a non-zero value in a
bool TdmMonteCarlo::checkCorrelation() const
{
aqOperations->DisableControls();
bool correlation = false;
int idCurrent = aqOperations->FieldByName("id")->AsInteger;
aqOperations->First();
while (!aqOperations->Eof)
{
if (aqOperations->FieldByName("correlation")->AsFloat != 0.0)
{
correlation = true;
break;
}
aqOperations->Next();
}
aqOperations->Locate("id",
AnsiString(idCurrent).c_str(),
TLocateOptions());
aqOperations->EnableControls();
return correlation;
}
The problem is that the last record is not being processed. In other
words, the /Eof/ property is becoming true just as the cursor moves to the
last record, not when it tries to go beyond it, as things normally work.
Does anybody have any idea of what could be causing this? I read somewhere
else that Eof might behave strangely when key fields are modified, but the
loop in question is a read-only one.
Thank you for any feedback.
--
Ney André de Mello Zunino
Ney André de Mello Zunino
2006-07-19 19:37:12 UTC
Permalink
Mark Guerrieri wrote:

Thanks for responding.
Post by Mark Guerrieri
What version are you using?
Borland C++ Builder 6 running on Windows XP (SP2).
Post by Mark Guerrieri
Do you have any filters in place?
None. It is a plain TADOQuery object with a simple select such as:

SELECT * FROM Operations WHERE well_id = <id>

Best regards,
--
Ney André de Mello Zunino
Mark Richards
2006-07-19 22:36:41 UTC
Permalink
Post by Ney André de Mello Zunino
while (!aqOperations->Eof)
{
if (aqOperations->FieldByName("correlation")->AsFloat != 0.0)
{
correlation = true;
break;
}
aqOperations->Next();
}
Have you checked the contents of the data? Your code suggests to me that
upon reaching a none numeric (ie. 0.o value) then you jump out5 of the loop.
Perhaps you have a record prior to the end which contains data other than
what you actually expect.
Ney André de Mello Zunino
2006-07-19 22:49:55 UTC
Permalink
Post by Mark Richards
Have you checked the contents of the data? Your code suggests to me that
upon reaching a none numeric (ie. 0.o value) then you jump out5 of the loop.
Perhaps you have a record prior to the end which contains data other than
what you actually expect.
Thanks for the suggestion. I have checked the data and there is nothing
wrong with it. I was working with a tiny dataset of 5 records. They all
hold floating-point numbers in the "correlation" column.

Regards,
--
Ney André de Mello Zunino
Continue reading on narkive:
Loading...