Subject Strange sorting and recordcount issue.
Author Adrian Wreyford
Dear List



I have a table ANIMAL that I populate from ANIMALLIST, that contains 820
animals.



I have a Query IB_QueryANIMAL with a number of animals ordered by age from
oldest to youngest, and assigned animal id from 1 to 820 consecutively.



The SQL for the Query is:

Select * from ANIMAL

ORDER BY ANIMALID

(PS I know * is not great, but just for the example).



In the application, I do the following:

On form.open

IB_QueryAnimal.Active := True;

IB_QueryAnimalList.Active := True;



I then run a script "Script1" with the following code:

DELETE FROM ANIMAL;

COMMIT WORK;



Script1.execute.



Now the animal table is empty, and using code I fill it with an ordered set
from animallist, from the oldest to the youngest animal, and assign an id
from 1 to 820 (ie 820 animals in ANIMALLIST), as I step through animallist.



Now ANIMAL contains the animals numbered by animalID 1 = Oldest, and 820 =
Youngest.



I then set n := IB_QueryAnimal.Recordcount;

IT RETURNS 821!!!!, and not 820?????



I then Call:

IB_QueryAnimal.First;



But find animal 820, and not animal 1 as I would expect. (Note it is ordered
on animalID, and I would expect 1 to be the first record.)



If I do everything as above, but insert the following code before setting
n := IB_QueryAnimal.Recordcount;

Ie.

IB_QueryAnimal.Close;

IB_QueryAnimal.Open;



And then

n := IB_QueryAnimal.Recordcount; now returns 820! And this is correct.

and then

IB_QueryAnimal.First;

I get animalID = 1; and this is also correct .. but why should I close -
open for this to work corectly?



Could anybody spare the time to explain this to me, as I'm baffled. I
allways thought a Query honours its SQL throughout.

Has the script got something to do with this?



Thanks in advance



Adrian





[Non-text portions of this message have been removed]