Skip to main content

Posts

Showing posts from October, 2016

POSTGRESQL: Dealing with 'current transaction is aborted, commands ignored until end of transaction block' in Lazarus/Delphi

Scenario:  Programming Environment: Lazarus/Delphi Database: PostgreSQL DB Component: Zeos Problem: You have a form displaying a table content in a grid. It is a typical data form where user can insert, update or delete record. When user inserting record which fails going through Table integriry constraints (foreign key, unique constraint, check constraints etc), postgresql will throw exception:  current transaction is aborted, commands ignored until end of transaction block. After this, all operation is not possible except closing the form and losing all modification you might have done. Solution: Define events of the query component, FDBConnection is db the connection component. BeforePost and BeforeDelete events: Self.FDBConnection.ExecuteDirect( 'SAVEPOINT mysavepoint'); AfterPost and AfterDelete events: Self.FDBConnection.ExecuteDirect( 'RELEASE SAVEPOINT mysavepoint'); OnPostError and OnDeleteError events: Self.FDBConnection.Ex