Subject Re: [IBO] Transaction and Datasets
Author Helen Borrie
At 05:09 PM 28/04/2004 +0700, you wrote:
>Dear All,
>
>Environment : Firebird 1.5, Delphi 6, IBO 4.2 (TDataset components)
>
>It's a very normal situation to have more than one dataset connected to
>a TIBOTransaction. Recently i came across a situation (a bug...:) where
>a TIBOQuery.Open() is called before the form had a chance to call
>TIBOTransaction.StartTransaction(), thus screwing up the transaction
>handling logic in my application.

When you assign explicit transactions, you must look after create order
properly. There's no magic to this: it's what you do in any well-formed
Delphi application, since, by nature, Delphi code creates dependencies
between objects.


>To prevent this in the future, i'm thinking about opening ALL TIBOQuery
>connected to a particular TIBOTransactions at the same time (which after
>i manually call StartTransaction()).

Not a wise solution. Just take care of creation order, assign the
ib_transaction property properly at design time, and things will happen safely.


>The question is : how can i do this with IBO ?
>Please keep in mind that the TIBOQuery do not necessarily reside in the
>same form/data module as the TIBOTransaction.

Again - creation order is the important thing. Forms and datamodules are
just containers. Objects in Delphi are not created in random order - they
are created in accordance with your design. A connection needs a session,
a transaction needs a connection, dataset objects need a transaction and a
connection, datasources need a dataset and data-aware controls need a
datasource. When you use <default> properties, the required objects will
be created if they are missing. When you drop in explicit objects, notably
session and transaction objects, and use those in place of the default
objects (a good practice) you must take care to reshuffle the creation
order. You do that by right-clicking on any data object.

Creation order also matters very much at the application level, regardless
of whether you use default session and transaction objects. If you are
using a datamodule, you'll need to go into the DPR and move it ahead in the
creation order, before any forms containing objects that refer to objects
in the datamodule.

>The property that looks promising was TIBOTransaction.Datasets[] and
>TIBOTransaction.DatasetCount, but the code below produced an access
>violation error in fbclient.dll. (Actually I didn't really expect it to
>work, since the elements of the property were TIB_Datasets instead of
>the TIBOxxxx components :D ).

You get AVs when you are not careful with creation and destruction of
objects and their dependencies.

>...
>assert(trans.inTransaction = false);
>trans.startTransaction();
>for i:=0 to trans.datasetcount-1 do begin
> trans.datasets[i].open;
>end;
>...

Don't look for hacks to solve a problem that can be fixed *properly* (i.e.
avoided) with very little effort. Hacks lead to more bugs and more hacks....

>PS: I also came across what I think is a bug in TIBOQuery regarding
>'select first n' queries. A simple statement like 'select first 5 from
>table' will cause a 'token unknown error, line 3 char 6'. Is this a
>known problem, or it's just me ? How do i report this to jwharton?

There was a parser bug with SELECT FIRST that was fixed long ago. But that
bug would not throw an "unknown token" error. Are you sure you are using
the correct client library? Did you run instclient.exe after you installed
Fb 1.5?

It could be that you have a very old version of IBO. There have been many
updates since IBO 4.2 (July 2001). What exactly does the Version property
on your Object Inspector tell you? Do you know that to use Fb 1.5 with IBO
lower than 4.3A you have to set OldParameterOrdering on in firebird.conf?

Helen