Jump to content
Skrim

Transactions

Recommended Posts

Hi

 

I have this code:

 

(Database is PostgreSql)

 

try

  aDatabase.starttransaction;

  ...

except

  on edatabaseerror do

  begin
    aDatabase.rollback;
  end;

end;

 

But what about a commit. Is it done automatically here, hence not necessary?

 

Regards,

Ole

Edited by Skrim
None

Share this post


Link to post

Hi...:classic_cool:

 

 try
  aDatabase.Starttransaction;
  ...
  aDatabase.Commit
except
  on edatabaseerror do
  begin
    aDatabase.Rollback;
  end;
end; 

Please use the "Code Tags" </> :classic_wink:

Share this post


Link to post
21 minutes ago, haentschman said:

Hi...:classic_cool:

 


 try
  aDatabase.Starttransaction;
  ...
  aDatabase.Commit
except
  on edatabaseerror do
  begin
    aDatabase.Rollback;
  end;
end; 

Please use the "Code Tags" </> :classic_wink:

Done.

 

Now, what is your answer to my question :classic_smile:

Share this post


Link to post
2 hours ago, David Heffernan said:

Just to be clear, what is aDatabase. I suppose the answer could depend on that information. 

It's a PostgreSql database.

Share this post


Link to post

I have done some testing, it seems I do need a Commit.

 

Without it the data is not saved to the database.

 

So at least using Postgresql and you start a transaction, you either have to commit or rollback.

 

Ole

 

 

Share this post


Link to post

As far as I know, that is the basic role of transactions. It is about covering data integrity.

Share this post


Link to post

Is you are using FireDAC than transactions are used internally, but you could use transactions like in your example.

The "commit" is required if the the DataSet is set to no auto commit, e.g. cached updates.

 

If I am wrong please correct me.

Share this post


Link to post
2 hours ago, Skrim said:

It's a PostgreSql database.

 No. I mean what is aDatabase, the variable in your code. What is that? What type. 

Share this post


Link to post

If you use the StartTransaction command, you have to finish it off with CommitTransacton or a  Rollback. If you're not using a StartTransaction, the FDConnection will start it for you and make a commit when your datasets are closed.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×