| View previous topic :: View next topic |
| Author |
Message |
Ney André de Mello Zunino Guest
|
Posted: Tue Jul 18, 2006 5:38 am Post subject: Last record not being processed |
|
|
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 |
|
| Back to top |
|
 |
Mark Guerrieri Guest
|
Posted: Wed Jul 19, 2006 8:45 pm Post subject: Re: Last record not being processed |
|
|
What version are you using?
Do you have any filters in place?
Mark
"Ney André de Mello Zunino" <zunino (AT) inf (DOT) ufsc.br> wrote in message
news:44bc2d8e$1 (AT) newsgroups (DOT) borland.com...
| Quote: | 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 |
|
|
| Back to top |
|
 |
Ney André de Mello Zunino Guest
|
Posted: Thu Jul 20, 2006 12:37 am Post subject: Re: Last record not being processed |
|
|
Mark Guerrieri wrote:
Thanks for responding.
| Quote: | What version are you using?
|
Borland C++ Builder 6 running on Windows XP (SP2).
| Quote: | 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 |
|
| Back to top |
|
 |
Mark Richards Guest
|
Posted: Thu Jul 20, 2006 3:36 am Post subject: Re: Last record not being processed |
|
|
| Quote: | 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. |
|
| Back to top |
|
 |
Ney André de Mello Zunino Guest
|
Posted: Thu Jul 20, 2006 3:49 am Post subject: Re: Last record not being processed |
|
|
Mark Richards wrote:
| Quote: | 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 |
|
| Back to top |
|
 |
|