Subject | Re: ApplyUpdates seems not to update DB directly |
---|---|
Author | Adam |
Post date | 2006-04-12T11:32:47Z |
--- In firebird-support@yahoogroups.com, "Antonio Cambule (STUEBER
SOFTWARE)" <Antonio.Cambule@...> wrote:
Generally, the structure would look something like below.
con.open;
try
tra.StartTransaction
try
...
qry.Open;
...
tra.commit;
except
tra.rollback;
raise;
end;
finally
con.Close
end;
If you are not explicitly committing your transaction, then it has a
default action that occurs before it is destroyed (which is probably
commit by default).
Rule:
No other transaction will see any change you have made to the data
until at least the time you commit your changes.
After that time, snapshot transactions that started before you
committed will ignore your changes, read-committed transactions that
started before you committed will now see your changes, and all new
transactions will see your changes.
Understanding how transactions work is really important in Firebird.
They are not an 'after thought' but an essential part of how the
database engine works. At first it may seem confusing but if your
application is written to make use of isolation, you are free from the
locking mechanisms you may be familiar with which has enourmous
performance benefits.
Adam
SOFTWARE)" <Antonio.Cambule@...> wrote:
>something.
> Hi,
>
> Enrivonment: FB 1.5.x, WinXP, Delphi 7 with IBX 7.07
>
> Scenario:
>
> * 1 x Connection to Database.
> * Access with: TIBQuery - TDataSetProvider - TClientDataSet
> (Set of Access Components).
> * Transaction default is set to TACommit (commit).
>
> My Application has different forms that show different data of my DB.
> Every Form has it's own DataModule that will be created when
> Form is created and will be destroyed when Form is destroyed.
> The most forms have PageControls, which open and close Master- and
> Details Data depending on which Page the user browses.
> DataModules hold the IBX Access components (TibQuery...) and almost one
> Transaction Component for all Sets of Access components in this module.
>
> What I do:
>
> - I go to Form A
> - Form A is created and shown, DataModule is created and Data is opened.
> - I change something, klick on save and it will be posted.
> - On AfterPost Event an Applyupdate is made.
>
> Data should be saved in Database now, am I wrong?
> Since here seems to be all right.
>
>
> - I change to Form B.
>
> < DataModule of Form A is has been destroyed. All Datasets of them are
> closed etc. >
>
> - Form B is created and shown, new DataModule for Form B
> is created and Data is opened.
> - An similar Data as in Form A will be opened to the same Table.
> - New DataModule, new Query, new Transaction.
>
>
> Problem:
>
> The Data is not updated. I get the state before the changes were made.
>
>
> What I know:
>
> When I close and restart my App and I go Form B then all is fine.
> And the new state is shown.
>
> But I don't want to close and reopen my App everytime I change
>Does ApplyUpdate actually commit your transaction? I wouldn't think so.
> Hope someone can help on this.
Generally, the structure would look something like below.
con.open;
try
tra.StartTransaction
try
...
qry.Open;
...
tra.commit;
except
tra.rollback;
raise;
end;
finally
con.Close
end;
If you are not explicitly committing your transaction, then it has a
default action that occurs before it is destroyed (which is probably
commit by default).
Rule:
No other transaction will see any change you have made to the data
until at least the time you commit your changes.
After that time, snapshot transactions that started before you
committed will ignore your changes, read-committed transactions that
started before you committed will now see your changes, and all new
transactions will see your changes.
Understanding how transactions work is really important in Firebird.
They are not an 'after thought' but an essential part of how the
database engine works. At first it may seem confusing but if your
application is written to make use of isolation, you are free from the
locking mechanisms you may be familiar with which has enourmous
performance benefits.
Adam