Subject Re: [IBO] is dataset empty
Author Paul Vinkenoog
Hello again,

> bool __fastcall CanEdit( TIB_Dataset *pDataset )
> {
> TIB_BDataset *pBD = dynamic_cast< TIB_BDataset* >( pDataset );
> if ( pBD )
> {
> return ! pBD->IsEmpty;
> }
> else
> {
> // either use my "APIFirst & test Eof" trick
> // or Luc's "Bof and Eof" test
> // ...both on pDataset of course, not on pBD!
> }
> }

I tried out the "Bof and Eof" test on a cursor of mine. It works, but
_only_ if you explicitly Open the cursor first. Normally you don't do
that, because First and APIFirst automatically open it. You also have
to make sure that the cursor is inactive before (re)opening it.

The behaviour of TIB_Cursor wrt Bof and Eof on an empty dataset turns
out to be:

1: Cursor prepared, but not yet opened (no Open, no First or APIFirst
executed): Bof true, Eof false.

2: After First or APIFirst: Bof false (!), Eof true.

3. Immediately after an explicit Open: Bof true, Eof true -- but only
if Active was false before the call to Open. (If Active was already
true, Open does nothing.)

So your "else" part becomes either:

{
pDataset->APIFirst();
return ! pDataset->Eof;
}

or:

{
pDataset->Active = false;
pDataset->Open(); // or: pDataset->Active = true;
return ! ( pDataset->Bof && pDataset->Eof );
}


Another thing; the IBO Help says for TIB_Cursor->Active:

When output is being requested, Active will be true if a prepared
statement was successfully executed and output exists.

This is incorrect. Even if there is no output (empty set, Bof and Eof
true) Active remains true.


Greetings,
Paul Vinkenoog