OracleSession1.CommitUpdates not working

Brooks

Member
What am I doing wrong that my changes are not getting written back to the database?

procedure TfrmMain.wwDSMediaGrpBeforePost(DataSet: TDataSet);
begin
try
OraSession1.CommitUpdates([wwDSMediaGrp]);
except
OraSession1.Rollback;
raise;
end;
end;

procedure TfrmMain.wwDSMediaGrpApplyRecord(Sender: TOracleDataSet; Action: Char; var Applied: Boolean; var NewRowId: String);
begin
try
OraSession1.ApplyUpdates([wwDSMediaGrp], False);
except
OraSession1.Rollback;
raise;
end;
OraSession1.CommitUpdates([wwDSMediaGrp]);
end;

------------------
Brooks Vaughn
brooks@tidalwave.net
 
There seems to be a misunderstanding here. CommitUpdates does not commit any changes to the database.

There is another method in TOracleSession: Commit, which does this part of the job.

When using Cached Updates you then also need to call CommitUpdates, which will let the OracleDataSet components that had pending updates recorded know that these updates have now been sent to the database.
 
So where do you suggest I put what code?

I finally got the record changes to post to the database.

I put the following in a AfterPost Event. I use this same event for the AfterDelete event as well.

How can I do things better?

-Brooks

procedure TfrmMain.ApplyUpdatesAfterPost(DataSet: TDataSet);
begin
with DataSet as TOraclewwDataSet do begin
OraSession1.ApplyUpdates([DataSet], True);
end;
end;

Originally posted by helene:
There seems to be a misunderstanding here. CommitUpdates does not commit any changes to the database.

There is another method in TOracleSession: Commit, which does this part of the job.

When using Cached Updates you then also need to call CommitUpdates, which will let the OracleDataSet components that had pending updates recorded know that these updates have now been sent to the database.

------------------
Brooks Vaughn
brooks@tidalwave.net
 
I haven't used the events you are mentioning myself. We have used a button which the user has to press to explicitly state she wants to store data. This invokes a method which is basically built this way

try
session.applyUpdates (Dataset1);
session.applyUpdates (Dataset2);
(if controlling the order in which datasets are stored is important)
session.commit;
Dataset1.CommitUpdates;
Dataset2.CommitUpdates;
except
Session.Rollback;
Raise;
end;

You should choose a method which gives you a good control of your transactions to the database, avoiding a large number of small transactions. This is good practice both to improve performance, (reduce network trafic and server transaction logging overhead) and also to ensure data consistency and integrity in your database. I am not so sure wheter using the events you mention will be good for achieving this.
 
I have tried this with success as follows but what is the difference between method #1 and #2?

Method #1:

procedure ApplyUpdatesAfterPost(DataSet: TDataSet);
begin
with DataSet as TOraclewwDataSet do begin
try
Session.ApplyUpdates([DataSet], False);
Session.Commit;
CommitUpdates;
except
Session.Rollback;
Raise;
end;
end;
end;

Method #2:

procedure ApplyUpdatesAfterPost(DataSet: TDataSet);
begin
with DataSet as TOraclewwDataSet do begin
Session.ApplyUpdates([DataSet], True);
end;
end;
 
Back
Top