Page 1 of 1

How can I make a normal transaction?

Posted: Wed 25 Jan 2017 12:25
by invent
Hello,

now I am desperate, because I cannot make the old transction behavoiour in InterBase.

The first help I got was:
To solve the issue you can use the following advice:
- use for dataset a separate transaction, not a default transaction TUniConnection;
- use for data modification UpdateTransaction.
That's impossible, because I have a project with 1 TUniConnection, circa 2000 TUniQueries and circa 800 TUniTables. I cannot add nearly 3000 transactions to this project.

The second idea was:
In order to provide backward compatibility with older UniDAC versions, we added the OldTransactionBehaviour global variable declared in "Uni.pas". The default variable value is "False". So, if you want to have old behaviour, you should set the variable to "True".
Okay, I set "OldTransactionBehaviour := true;". But this not enough, because Rollback has not worked. See here: viewtopic.php?f=28&t=34870

There ViktorV wrote:
So, to solve the issue, please set the AutoCommit property to False for TUniConnection or dataset.
When I set TUniConnetcion.AutoConnect = false, I have to add ten thousands of commits to my project. Or I have to change 3000 Datasets. This is not practical.

Since more than 20 years the normal use of transactions is:

Code: Select all

UniConnection1.StartTransaction;
try
  ( .. make some changes ...)
  UniTable1.Post;
  UniTable2.Post;
  UniTable3.Post;
  UniConnection1.Commit;
except
  UniConnection1.Rollback;
end;
How can I realize this with UniDac 6.4 and InterBase?

BTW, my project works with InterBase, MS SQL Server, Oracle and PostgreSQL. I need one code for all. That's my reason for the use of UniDAC.

Kind regards,
Gerd Brinkmann
invent GmbH

Re: How can I make a normal transaction?

Posted: Thu 26 Jan 2017 10:45
by ViktorV
You can try to solve the issue in the following way: set the TUniConnection.AutoCommit property to False before calling TUniConnection.StartTransaction and to True after executing the TUniConnection.Commit methods (TUniConnection.Rollback). For this you can declare the descendant of TUniConnection and override the necessary methods. For example:

Code: Select all

  TMyUniConnection = class(TUniConnection)
  public
    procedure StartTransaction; override;
    procedure Commit; override;
    procedure Rollback; override;
  end;
...
  procedure TMyUniConnection.StartTransaction;
  begin 
    if GetProvider.GetProviderName = 'InterBase' then
      AutoCommit := False;
    inherited StartTransaction;
  end;

  procedure  TMyUniConnection.Commit;
  begin
    inherited Commit;
    if GetProvider.GetProviderName = 'InterBase' then
      AutoCommit := True;
  end;

  procedure TMyUniConnection.Rollback;
  begin
    inherited Rollback;
    if GetProvider.GetProviderName = 'InterBase' then
      AutoCommit := True;
  end;