PgDAC

TPgConnection.AutoCommit Property

Permits or prevents permanent updates, insertions, and deletions of data associated with the current transaction against the database server.

Class

TPgConnection

Syntax

property AutoCommit: boolean;

Remarks

Use the AutoCommit property to permit or prevent permanent updates, insertions, and deletions of data associated with the current transaction against the database server without explicit calls to the Commit or Rollback methods.

Set AutoCommit to True to permit an implicit call to the Commit method after every database operation.

The AutoCommit property in TPgConnection has higher priority than the same properties in dataset components. Its default value is True.

Note: The AutoCommit property in TPgConnection globally defines whether all database modification queries are committed implicitly or not. Components descending from the TCustomDADataSet and TCustomDASQL classes inherit their AutoCommit properties. This allows them to determine their implicit transaction and then choose when to commit the behavior, specifically after each data-modifying access.

This is an example of a procedure that removes all records from the Dept table and makes this change permanent.

Example

procedure TForm1.DeleteClick(Sender: TObject);
begin
   PgQuery.Session := OraSession;
   PgConnection.AutoCommit := True;
   PgQuery.AutoCommit := False;
   PgQuery.SQL.Text := 'DELETE FROM Dept';
   PgQuery.Execute;         // delete all records, commit is not performed
   PgConnection.Rollback;// restore deleted records 
   PgConnection.AutoCommit := False;
   PgQuery.AutoCommit := True;
   PgQuery.SQL.Text := 'DELETE FROM Dept';
   PgQuery.Execute;         // delete all records, commit is not performed
   PgConnection.Rollback; // restore deleted records 
   PgConnection.AutoCommit := True;
   PgQuery.AutoCommit := True;
   PgQuery.SQL.Text := 'DELETE FROM Dept';
   PgQuery.Execute;         // delete all records, commit is performed
   PgConnection.Rollback; // couldn't restore deleted records 
end; 

See Also

© 1997-2025 Devart. All Rights Reserved. Request Support DAC Forum Provide Feedback