Subject | RE: [IBO] Getting validation source from a domain |
---|---|
Author | Jason L. Wharton |
Post date | 2006-10-19T06:47:28Z |
> I am using the code below to try to get the validation source for aIn IBO StartTransaction only has to do with the explict transaction status
> domain--but it doesn't return anything. I try the same SQL in IBExpert
> (which last I knew used IBO) and it returns a value... what am I
> forgetting?
> lCursor := CreateCursor('SELECT First 1 RDB$VALIDATION_SOURCE
> FROM RDB$FIELDS WHERE RDB$FIELD_NAME = ''%s''',
> [UpperCase(aName)]);
> try
> try
> if not ({FTx.TransactionIsActive or} FTx.InTransaction) then
> FTx.StartTransaction;
> lCursor.First{Open};
> result := not lCursor.Eof{RecordCount > 0};
> if result then
> aValidationSource := lCursor.Fields[0].AsString
> else
> aValidationSource := '';
> FTx.Commit;
> except
> FTx.Rollback;
> raise;
> end;
> finally
> lCursor.Free;
> end;
>
of the TIB_Transaction component. Therefore, it is inappropriate to do an
OR with TransactionIsActive. It only corresponds with InTransaction alone.
If you are using a TIB_Cursor then don't make a reference to the RecordCount
property. Call the First method and then check for Eof. Calling
RecordCount will cause a separate query to be sent to the server just to get
the count. Being that the dataset is unbuffered it can only know that by
doing a separate query. Also, calling Open on a TIB_Cursor does not
necessarily automatically fetch the first record and so the cursor remains
at Bof and thus no data will be returned. You should either call Open and
then call Next or just call the First method to open and fetch the first
record.
TIB_Cursor behaves differently than a buffered query. If you are not using
a TIB_Cursor then you will need to take what I've said here with a grain of
salt.
I put some corrections to your code above.
Also, as a word of advice. You should either have a transaction start and
end in a method or if you detect a transaction is active at the start you
should leave the transaction open upon exit. So, save your transaction
state in a local flag and only commit if there wasn't a transaction active.
Otherwise, what I see that could happen is you may be in a transaction that
you don't want to end yet and call a global routine and end up having a
transaction prematurely committed.
HTH,
Jason Whartons