Page 1 of 1

How to avoid auto commit with TPgSQL.execute

Posted: Tue 10 Nov 2020 10:16
by jmt
Hi,
I might miss something, but I can't find any option to avoid auto commit when using TPgSQL.execute.

Let assume I have different methods using TPgSQL to update, delete or insert data to different tables and all using the same TPgConnection. And I want the caller of those methods or even the caller of the caller to decide when to commit or rollback the data.

How to achieve that?

I read about the AutoCommit property that is available for TPgQuery but with my small test it looks like even it's set to false, the execute method of TPGQuery does a commit. So, using TPgQuery instead doesn't looks like a workaround.

Appreciacte any advice.
Thanks

Re: How to avoid auto commit with TPgSQL.execute

Posted: Thu 12 Nov 2020 16:33
by oleg0k
Hello,
You should manually start the transaction for TPgConnection: PgConnection.StartTransaction, and then commit or rollback the transaction after performing the necessary operations: PgConnection.Commit or PgConnection.Rollback, respectively. Visit our documentation for more information: https://www.devart.com/pgdac/docs/devar ... tion().htm

wbr, Oleg
Devart Team

Re: How to avoid auto commit with TPgSQL.execute

Posted: Thu 19 Nov 2020 12:39
by jmt
In other words AutoCommit is not working?

But what if a manual start transaction is not an option?

Re: How to avoid auto commit with TPgSQL.execute

Posted: Mon 23 Nov 2020 18:46
by oleg0k
Hello,
Some database systems, e.g., Oracle, allow executing DML statements without a commit statement, but that's not the case for PostgreSQL. We'll consider the possibility of implementing an implicit transaction start when AutoCommit=False. Currently the only way to control transactions in PgDAC is to manually start them with StartTransaction and end with Commmit or Rollback when necessary.

wbr, Oleg
Devart Team