Subject Re: [IBO] Sequence of changes under transaction
Author Svein Erling Tysvaer
At 12:55 13.06.2003 +0000, you wrote:
>Can I trust the sequence of edits and changes done by triggers under
>transaction control ?
>My situtation is this
>I am Using Delphi 5 and the Tdataset compatible IBO components.
>I have a table Members with a balance-field among other things.
>I have a table Postings with payments etc... This table has a trigger
>updates the Balance-field of the member (OnAfterInsert)
>When receiving a payment I open the member table to find the
>name/adress and
>balance of the member.
>I *may* put the Member table in edit-state (the operator may edit some
>When the operator finishes entering payment info I start the
>then post the member table and then insert the payment-record, so
>that the
>trigger updating of the Balance comes last.
>Finally commiting the changes.
>(I did first have an error in updating balance due to the fact that I
>posting the member with its original contents AFTER the trigger had
>the balance-field)
>My problem is now that *sometimes* the balance is not right as if it
>has not
>been updated by the trigger or as if the update is overwritten with
>original balance.
>So my question is: Is it possible that this sequence can be reverted
>in some
>cases ?

No, the most likely reason for this is concurrent updating. I.e. you start
one transaction and then another one before the first transaction commits.
This means that these two transactions do not see each others changes and
both transactions will update the balance as if the other transaction had
never inserted anything. By the way, you cannot have a table open except
within a transaction. So one physical transaction is started once you open
your members table - depending on your settings this may or may not be the
same as the one you logically think you are starting at a later point in time.