Subject Re: [IBO] TIB_DSQL-prevent exception on empty result
Author Helen Borrie
At 04:33 PM 17/05/2005 +0200, you wrote:
>I'm using TIB_DSQL to do a number of single record based
>operations and it's working fine, but ...
> sSQL:='select first(1) REF from '+MainQuery.Tablename+' '+
> 'Where (('+SortIndex+'<:P1) or ('+SortIndex+'=:P1 and
>REF<:P2)) '+
> 'Order by '+SortIndex+' DESC,REF DESC';
> SearchQuery.sql.clear;
> SearchQuery.sql.add(ssql);
> SearchQuery.Prepare;
> SearchQuery.Params[0].AsString:=Suchbegriff;
> SearchQuery.Params[1].Asinteger:=RefAlt;
> try
> SearchQuery.ExecSQL;
> RefNeu:=SearchQuery.FieldByName('REF').AsInteger;
> MainQuery.ParamByName('REFNO').AsInteger:=RefNeu;
> Except //kein neuer Satz gefunden; also den letzten Ansteuern
> SQL_First_Ref_on_actual_Sort(MainQuery,SearchQuery);
> End;
>My question(s):
>1. The ExecSQL is firing an Debugger Exception, if the result of the
>sql is empty. How can this Exception be prevented?

Don't use a SELECT statement in a IB_DSQL - it is not a dataset
component. It can receive return parameters from executing an executable
stored procedure, but not a dataset from a cursor. Use an IB_Cursor and
call its First method (not Open).

>2. If there is a solution for 1., how do I determine, if the result
>"isempty"? I haven't found a function like tib_query.isempty.

with myIB_Cursor do
if (EOF and BOF) then // equivalent to IsEmpty