Subject RE: [IBO] check for empty dataset
Author Paul Vinkenoog
Hi Ronan,

>> Use a cursor and call First and then check to see if it is EOF. If
>> not then just ignore the returned record.

> Thanks for your reply. Is there an example of how to use cursors
> that you can direct me towards?

You use them much like Queries: assign the SQL ("SELECT BLAH1, BLAH2
FROM WHATEVER") at design time or runtime, and then, in your case:

if not MyCursor.Prepared then MyCursor.Prepare;
// don't Open a cursor; (API)First will "open" it:
MyCursor.First; // or, faster: APIFirst
if MyCursor.Eof
then ... // dataset was empty
else ... // dataset contains at least one record

Of course you can also design a singleton query like

SELECT COUNT(*) FROM ... WHERE ...

...which can be executed through a TIB_DSQL. Or (faster in case of big
datasets):

SELECT 1 FROM RDB$DATABASE WHERE EXISTS
(SELECT THISFIELD, THATFIELD FROM MYDATASET WHERE ...)

This last one returns 1 if the set contains records, NULL (not 0) if
it's empty.


Greetings,
Paul Vinkenoog