Disabling AutoCommit

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
horsi
Posts: 14
Joined: Sat 15 Jan 2011 07:19

Disabling AutoCommit

Post by horsi » Thu 27 Oct 2011 08:48

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?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 27 Oct 2011 13:46

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;

horsi
Posts: 14
Joined: Sat 15 Jan 2011 07:19

Post by horsi » Thu 27 Oct 2011 14:16

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;

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 31 Oct 2011 14:45

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.

Post Reply