Subject Re: [IBO] In multiuser system
Author Helen Borrie
At 01:55 AM 21-10-02 +0200, you wrote:
>Hi,
>
>In multiuser system:
>
>- Is the call of the StartTransaction necessary or
> the transaction will start with Query open or
> Insert/Update/Delete?

A transaction wraps around a unit of work which, in the default situation,
involves all of your query objects. A transaction is needed for any query
request, including the SELECT. Once a transaction is started, it remains
started until your application either commits it or rolls it back.

IBO in general takes care of starting a transaction if there is not one
currently started. It also takes care of the COMMIT call if your
transaction is set up with Autocommit true.

With Autocommit false, your application must take care to complete the
transaction each time a unit of work is complete. Autocommit will become
false if you call StartTransaction explicitly so, in this situation, you
must call Commit or Rollback to end the transaction.

> At the moment I call the StartTransaction method in all
> the OnBeforeInsert, OnBeforeEdit, OnBeforeDelete event
> of my Queries. Is this all right or how else should I do it?

No, it is not alright to do this. You will get an error if you call
StartTransaction and the transaction is already started. If you have an
open dataset then, in most cases, there is already a transaction
running. You can include code to test whether the transaction is started
and, if it is not, to call StartTransaction:

with MyQuery do begin
if not ib_transaction.Started then
ib_transaction.StartTransaction;
....
end;

Instead of Started you can use TransactionIsActive to determine whether the
dataset has updates pending. It is often more useful, since Started merely
tests whether there is a transaction and not whether some work is actually
pending.

with MyQuery do begin
if not ib_transaction.TransactionIsActive then
ib_transaction.StartTransaction;
....
end;


>- To close a transaction which methods can be used?
> The Refresh( true / false ) or
> CommitRetaining / RollbackRetaining and TIB_Dataset.Refresh?

Only Commit, Rollback, CommitRetaining and RollbackRetaining will close a
transaction. The latter two will start a new transaction using the same
view of the datasets that existed before the call.

You can call the Refresh method **of the transaction** and pass True as its
argument to have the transaction commit all outstanding work and close and
reopen all of the datasets. If you pass False, the outstanding work will
be rolled back.

Datasets also have a Refresh method, which closes and reopens the dataset
without committing or rolling back anything.

Helen