Subject Re: Record count alternative
Author Adam
> I know that record counts are a slow process in FB and are to be
> avoided. I am doing an ordering app where the results of a
(sometimes)
> complex query are displayed. The client wants it to automatically
order
> the item if only one result is returned, which is reasonable.
However
> to determine if there is only one result I think I need to either
do a
>
> a) Query.RecordCount
> b) Move to the next record, if EOF than only one returned, move
back again.
>
> Is there a better way?

I am guessing that you don't want to splice a not exists clause into
the query itself in some sort of case statement. I would go for b,
but use a common function to do it, and name it so it is obvious what
you are doing. From memory, you are using delphi, otherwise you can
translate it to whatever.

function OnlyContainsOneRecord(qry : TDataset) : Boolean;
var
function IsFirstRecord : Boolean;
begin
qry.Prior;
Result := qry.BOF;
if not Result then qry.Next;
end;

function IsLastRecord : Boolean;
begin
qry.Next;
Result := qry.EOF;
if not Result then qry.Prior;
end;

begin
Result := (IsFirstRecord and IsLastRecord);
end;

Now your code is perfectly intuitive;

if OnlyContainsOneRecord(Query) then OrderProduct;

Adam