Skip to main content

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.ExecuteDirect( 'ROLLBACK TO SAVEPOINT mysavepoint');

Note: you can change mysavepoint with any valid identifier name.

Comments

Popular posts from this blog

Install Sketchup 2017 64 bits on Linux Ubuntu 16.04 64 bits

Install Sketchup 2017 64 bits on Linux Ubuntu 16.04 64 bits: 1.Enable 32 bit architecture: $sudo dpkg --add-architecture i386  2. Set wine PPA $sudo add-apt-repository ppa:wine/wine-builds Update repository $sudo apt-get update 3. Install wine newest staging branch version $sudo apt-get install --install-recommends winehq-staging 4. Ensure we get a 64bits wine, edit file ~/.profile and locate for text: export WINEARCH= If the value is win64 you are good, if the value is win32 change it to win64. Save the file. Ensure the environment variable also set to win64 by typing command: $export WINEARCH=win64 5. Download winetricks: $wget https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks    Don't forget to set the attribute so it is executable $chmod +x winetricks 6. Run winetricks $./winetricks Inside winetricks: Choose Select the default wineprefix, click OK Choose Install a Windows DLL or component, click OK Choos

Program timbangan elektronik, sebuah program Windows yang dijalankan di Linux.

Kemarin, mumpung hari libur aku setup program timbangan digital baru di kantor. Program yang lama merupakan program DOS yang aku tulis dengan menggunakan Clipper, program ini berjalan dengan baik di linux dengan bantuan dosemu. Program baru merupakan program Windows. Salah satu improvement dalam program ini adalah support untuk beberapa jenis indikator. Program diinstall di linux dengan wine versi 1.1.20. Beberapa catatan dalam instalasi program ini di wine: Pencetakan slip bukti timbangan dan laporan-2 menggunakan printer Dot Matrix. Apabila pencetakan dilakukan lewat printer driver, pencetakan dengan printer dot matrix akan menjadi sangat lambat plus hasil buruk plus boros pita... :) Oleh karena itu, program ini melakukan pencetakan langsung melalui printer port lpt1. Di windows, hal ini tidak menjadi suatu permasalahan, di linux dengan wine, maka lpt1 akan dimap ke /dev/lp0. Masalahnya, owner dari device ini adalah root dan group lp. Secara default user-user di Ubuntu (..nggak tahu

Disabling middle click paste and close in ubuntu 18.04 by enabling /etc/rc.local

How to disable middle click button in ubuntu 18.04 by enabling /etc/rc.local Create or edit/etc/rc.local file #!/bin/bash xinput set-button-map 11 1 0 3 exit 0 Make sure it is executable $sudo chmod 755 /etc/rc.local Edit rc-local.service file sudo vim /etc/systemd/system/rc-local.service   Add this section [Install]  WantedBy=multi-user.target Enable the service sudo systemctl enable rc-local