Page 1 of 1

Disabling AutoCommit

Posted: Thu 27 Oct 2011 08:48
by horsi
Do UniDACs will work correctly when I disable AutoCommit manually on a TUniConnection with Oracle database provider?

Code: Select all

type THackUniConnection = class(TUniConnection);
...
THackUniConnection(UniConnection).AutoCommit := False;
PS.
Method "TUniConnection.AssignConnect" skips "TCustomDAConnection.FAutoCommit". Is this by design?

Posted: Thu 27 Oct 2011 13:46
by AlexP
Hello,

To change the properties AutoCommit, you need to define it after establishing connection to the database:

Code: Select all

  
  type THackUniConnection = class(TUniConnection);   
  ....
  UniConnection1.Connect;
  UniConnection1.StartTransaction;
  THackUniConnection(UniConnection1).AutoCommit := False;
  UniConnection1.ExecSQL('INTO TEST_TABLE(SOMEVALUE) VALUES(1)',[]);
  UniConnection1.Disconnect;

Posted: Thu 27 Oct 2011 14:16
by horsi
AlexP wrote:To change the properties AutoCommit, you need to define it after establishing connection to the database:

Code: Select all

  
  type THackUniConnection = class(TUniConnection);   
  ....
  UniConnection1.Connect;
  UniConnection1.StartTransaction;
  THackUniConnection(UniConnection1).AutoCommit := False;
  UniConnection1.ExecSQL('INTO TEST_TABLE(SOMEVALUE) VALUES(1)',[]);
  UniConnection1.Disconnect;
Is it necessary to start a transaction as You wrote?
Or maybe is it enough to change this parameter just after establishing connection, like this?

Code: Select all

  
  type THackUniConnection = class(TUniConnection);   
  ....
  UniConnection1.Connect;
  THackUniConnection(UniConnection1).AutoCommit := False;

Posted: Mon 31 Oct 2011 14:45
by AlexP
Hello,

Setting AutoCommit to false influences only behaviour on executing DML operations, i.e. if AutoCommit is set to false, data will not be saved to database immediately on executing Insert/Update/Delete operations, but on closing connection (on calling the OCISessionEnd method from Oci.dll) all data will be written to the database (standard Oracle behaviour). That's why you need to call the StartTransaction and RollBack methods explicitly.