Subject [IBO] Re: Connect "Transaction to Connection" or "Connection to Transaction"
Author Marco Menardi
--- In IBObjects@y..., Raymond Kennington <progsol@c...> wrote:
> Hmm. This concept is a bit of a twister.
>
> I understand it as follows. Please correct me if I'm wrong.
>
> The connection has a default transaction, but this property could be
set to a component Trans1 if one wants to have
> special processing or setup special properties associated with all
datasets that use the default transaction, Trans1.
> That is, Trans1 becomes the default transaction.

Absolutely right
>
> On the same form one could have another dataset that requires a
completely different transaction, Trans2, with different
> properties and event-processing to the default transaction, Trans1,
and both of these transactions could temporally be
> open during overlapping periods.

Yes, of course. Every activity (even select) of datasets are done
inside transactions. So, for instance, I've a transaction for lookups
queries, one or more for special works, one default with
autocommit=true for base table manteniance (i.e. customers, contacts,
etc.), and often they are open at the same time.

>
> Although it is possible to connect a transaction to a connection and
the same connection to the same transaction, it has
> the same effect as setting only the default transaction in the
connection component to the transaction component.

Right.

My rule is: use a transaction based of a conservative setup
(autocommit, read committed, etc.) and assign it to the connection as
a default transaction.
Set IB_Query transaction (to a specialized transactio) when you need
to encapsulate query work inside a "special" transaction, or group
queries that work together inside the same one.
Remember that: autocommit does not perform a commit, but a
commitretaining, so for "real work", not to stress firebird server,
you need explicitly started/committed transaction. If you are
inserting orders, don't rely upon the default connection transaction,
use a brand new (trsOrders), and assign it to query related to order
inserting. After you have done the work (inserted one item),
trsOrders.Commit.
You can set the query behaviour when commit is issued (caClose,
caInvalidate, ca....), since default value closes the queries (that's
not bad, just you have to know it, or you will be surprised that all
your data disapperared ;)

For simple data entry, I've a specialized component, IB_WorkBar and a
specialized Form I iherit from. For harder work, I've buttons linked
to code that does and manages transaction stuff.

Read Tech Info Sheets that are about transactions. It's really hard to
"understand" with a Paradox background like mine, but step by step I
hope I will master that concept ;)

regards
Marco Menardi