Skrim 11 Posted October 10, 2021 (edited) 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 October 10, 2021 by Skrim None Share this post Link to post
haentschman 92 Posted October 10, 2021 Hi... try aDatabase.Starttransaction; ... aDatabase.Commit except on edatabaseerror do begin aDatabase.Rollback; end; end; Please use the "Code Tags" </> Share this post Link to post
Skrim 11 Posted October 10, 2021 21 minutes ago, haentschman said: Hi... try aDatabase.Starttransaction; ... aDatabase.Commit except on edatabaseerror do begin aDatabase.Rollback; end; end; Please use the "Code Tags" </> Done. Now, what is your answer to my question Share this post Link to post
David Heffernan 2345 Posted October 10, 2021 Just to be clear, what is aDatabase. I suppose the answer could depend on that information. Share this post Link to post
Skrim 11 Posted October 10, 2021 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
Skrim 11 Posted October 10, 2021 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
Stano 143 Posted October 10, 2021 As far as I know, that is the basic role of transactions. It is about covering data integrity. Share this post Link to post
Ruslan 5 Posted October 10, 2021 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
David Heffernan 2345 Posted October 10, 2021 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
Hans J. Ellingsgaard 21 Posted October 10, 2021 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