How to use TpgQuery.AutoCommit properly?

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Wodzu
Posts: 23
Joined: Thu 01 Sep 2011 08:35

How to use TpgQuery.AutoCommit properly?

Post by Wodzu » Thu 04 Feb 2016 08:46

Hello,

first of all I wanted to report that help is missing information about the AutoCommit property. Could you explain a little how this property works because when I use this code:

Code: Select all

 
  PgQuery1.SQL.Text := 'INSERT INTO master (device_id, type) VALUES(:P_device_id, :P_type'); 
  PgQuery1.Connection.Connected := True;
  PgQuery1.AutoCommit := False;
  PgQuery1.Params[0].Value := 101;
  PgQuery1.Params[1].Value := 'some text';
  PgQuery1.ExecSQL;
The query still inserts one row into the table. I would expect that the row will not be inserted because AutoCommit is false.

Regards.

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: How to use TpgQuery.AutoCommit properly?

Post by azyk » Fri 05 Feb 2016 09:59

The AutoCommit property is not yet implemented in PgDAC, therefore its description is absent in documentation. Currently, we are developing a TPgTransaction component. As soon as this component is implemented, the AutoCommit property will be implemented along with it. We are going to release them in one of the next PgDAC versions.

Wodzu
Posts: 23
Joined: Thu 01 Sep 2011 08:35

Re: How to use TpgQuery.AutoCommit properly?

Post by Wodzu » Fri 05 Feb 2016 16:16

Thank you for your answer. Maybe it would be better to explicitly state in documentation that this feature is not yet implemented because now it causes confusion.

I was gonna ask how to pass a transaction between queries but I guess currently it is not possible.
May I have a suggestion? When implementing transaction object, please allow to pass it to the method: TpgConnection.ExecSQL() as well. Because now ExecSQL causes automatic commit after execution and sometimes it is better to do (pseudocode):

Code: Select all

Transaction: TpgTransaction;
Connection: TpgConnection;

Transaction.Active := True;
Connection.ExecSQL(SomeQuery, Transaction);
Connection.ExecSQL(SomeQuery, Transaction);
Connection.ExecSQL(SomeQuery, Transaction);
Transaction.Commit;

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: How to use TpgQuery.AutoCommit properly?

Post by azyk » Thu 11 Feb 2016 09:00

Thank you for your comments. We will try to take them into account when implementing transactions (including TPgTransaction) in PgDAC.

Wodzu
Posts: 23
Joined: Thu 01 Sep 2011 08:35

Re: How to use TpgQuery.AutoCommit properly?

Post by Wodzu » Thu 11 Feb 2016 19:12

Thank you for listening to your customers.

Post Reply