Link to home
Start Free TrialLog in
Avatar of kacor
kacorFlag for Hungary

asked on

IBExpress CommitRetaining

Hi Experts,

I develope an InterBase application with IBExpress components. On the DataModule there are TIBDatabase, TIBTransaction, TIBDataset components. On the Main form the DBNavigator has the procedure DBNavigatorClick which includes the following row:
if Button = nbPost then DM.IBTransaction1.CommitRetaining;

After each record I see the new rows but after closing the application the new data disappear. What is wrong?

wbr

Janos
Avatar of kacor
kacor
Flag of Hungary image

ASKER

I tried with

   if Button = nbPost then
   begin
      DM.DataSet1.Transaction.Commit;
      DM.dsUjRaktariTetel.Active := True;
   end;

but in this case nothing changes, the new data don't appear

wbr

Janos
Avatar of kacor

ASKER

sorry for the mistake

   if Button = nbPost then
  begin
     DM.DataSet1.Transaction.Commit;
     DM.DataSet1.Active := True;
  end;
Avatar of kacor

ASKER

Delphi 6 + InterBase 6
Avatar of Deesy
Deesy

How are you doing, Janos?!

Try use dataset.AfterPost Event instead dbnavigator events.
Again, I would not suggest use CommitRetaining/RolbackRetaining. Try don't use that construstion.

All the best,
Aleksey Emelyanov
Avatar of kacor

ASKER

The event "DBNavigator.OnClick" occurs when a button on the database navigator is clicked, after the action is executed. E.g. is the same as the "Dataset.AfterPost" Event I mean.

Otherwise I replaced the earlier script on the form with

procedure TDM.dsUjRaktariTetelAfterPost(DataSet: TDataSet);
begin
   dsUjRaktariTetel.Transaction.Commit;
   dsUjRaktariTetel.Active := True;
end;

on the datamodule but no changes unfortunately.

Janos
try this:

procedure TDM.dsUjRaktariTetelBeforePost(DataSet: TDataSet);
begin
  DataSet.Transaction := Transaction;
  Transaction.DefaultAction := taCommit;
  if not Transaction.InTransaction then
  begin
    DataSet.Database.DefaultTransaction := Transaction;
    Transaction.StartTransaction;
  end;
end;

procedure TDM.dsUjRaktariTetelAfterPost(DataSet: TDataSet);
begin
  try
    if Transaction.InTransaction then
    try
      Transaction.Commit;
    except
      Transaction.Rollback;
    end;
  finally
    DataSet.Active := False;
    DataSet.Prepare;
    DataSet.Open;
    DataSet.Locate('ID', DataSet.FieldByName('ID').AsString, []);
  end;
end;

emil
sorry, please ignore:
   DataSet.Locate('ID', DataSet.FieldByName('ID').AsString, []);

emil
Avatar of kacor

ASKER

Hi emil,

thank you for your help. Now I'll travel for 10 days and now I can't to test your proposition only after returning.

Sorry for this delay

with best regards

Janos
Avatar of kacor

ASKER

Hi emil,
I am now back. I tried, but I've got the messages:

[Error] AdatModul.pas(84): Undeclared identifier: 'Transaction'
[Error] AdatModul.pas(85): Missing operator or semicolon
[Error] AdatModul.pas(86): 'THEN' expected but identifier 'InTransaction' found
[Error] AdatModul.pas(88): Undeclared identifier: 'Database'
[Error] AdatModul.pas(89): Missing operator or semicolon
[Error] AdatModul.pas(96): Undeclared identifier: 'Transaction'
[Error] AdatModul.pas(96): 'THEN' expected but identifier 'InTransaction' found
[Error] AdatModul.pas(98): Missing operator or semicolon
[Error] AdatModul.pas(100): Missing operator or semicolon
[Error] AdatModul.pas(104): Undeclared identifier: 'Prepare'
[Fatal Error] Browse.dpr(7): Could not compile used unit 'AdatModul.pas'

Have I to declare the variable Transaction and Database, or ... ? Waiting for your comment

wbr Janos
sorry about my mistakes:

procedure TDM.dsUjRaktariTetelBeforePost(DataSet: TDataSet);
begin
 DataSet.Transaction := Transaction;
 DataSet.Transaction.DefaultAction := taCommit;
 if not DataSet.Transaction.InTransaction then
 begin
   DataSet.Database.DefaultTransaction := Transaction;
   DataSet.Transaction.StartTransaction;
 end;
end;

procedure TDM.dsUjRaktariTetelAfterPost(DataSet: TDataSet);
begin
 try
   if DataSet.Transaction.InTransaction then
   try
     DataSet.Transaction.Commit;
   except
     DataSet.Transaction.Rollback;
   end;
 finally
   DataSet.Active := False;
   DataSet.Prepare;
   DataSet.Open;
 end;
end;

emil
Avatar of kacor

ASKER

Hi emil,

I use D6 and as I tried to compile the proposed source code I've got a lot of error again. Then I placed your code between brackets and I tried to repeat by hand what you proposed. And for DataSet is no valid property Transaction  according to the code completion list only Tag and Translate. How can I round this ?

wbr Janos
Avatar of kacor

ASKER

And so InTransaction, Database andPrepare are also not valid properties for DataSet
ASKER CERTIFIED SOLUTION
Avatar of esoftbg
esoftbg
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I so sorry, but I have big problems with my internet provider and I am online very rarely...
It is my mistake:
I am thinking about TIB components
but you need about dbExpress components
Sorry,
emil
Avatar of kacor

ASKER

Emil and Aleksey,

thank you both for supporting me. I can't finish what I begun because I have most urgent todo but after finishing I'll contnue.

I hope we will meet us in the future

with best regards

Janos