trouble getting postgresql error message

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

trouble getting postgresql error message

Post by dschuch » Sun 27 Feb 2011 15:37

Hy, i have some trouble getting the correct error message from the postgres server to the client. it seems like a pgdac problem.

serverside the error is raised like that:

ERROR: update or delete on table "art" violates foreign key constraint "artoption_arts_aph_ak_nr_fkey" on table "artoption_arts"
SQL Status:23503
Detail:Key (ak_nr)=(TEST) is still referenced from table "artoption_arts".

(also shown in psql)

@ the client, only the first part of the error message is visble. (the content after ERROR:)
The SQL Status is missing as well as the important DETAIL part.

what to do, to get the important detail part through PGDAC to the user. I'm sure, in earlier versions that worked well. (much earlier, think the problem is about a half year, but i thought the reason was that we upgraded from postgres 81 to 90, but that isnt the reason, the error from the server is correct).


PS:

i checked that with ado too, here the error message looks like that:

update or delete on table "art" violates foreign key constraint "artoption_arts_aph_ak_nr_fkey" on table "artoption_arts"
Key (ak_nr)=(TEST) is still referenced from table "artoption_arts".

... so the user can see the ERROR and DETAIL part. SQL Status is hidden, like in PGDAC too, thats ok.
Last edited by dschuch on Sun 27 Feb 2011 17:22, edited 1 time in total.

dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Post by dschuch » Sun 27 Feb 2011 17:17

xxx
Last edited by dschuch on Sun 27 Feb 2011 17:20, edited 1 time in total.

dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Post by dschuch » Sun 27 Feb 2011 17:19

i was a bit confused now - with a UPDATE and ForeignKey violations the current error message seems ok. Both tables are in the error message, so the user can read the message (both tables are there >Update on table >>articles>customers<<) without the DETAILS part.

but with insert violations the second tablename isnt clear:

LOLL1=# INSERT INTO art (ak_ac, ak_nr) VALUES ('XXAS', 'XYZ');
ERROR: insert or update on table "art" violates foreign key constraint "art_ak_ac_fkey"
DETAIL: Key (ak_ac)=(XXAS) is not present in table "artcod".

the user cant know the backgrounds of foreign key "art_ak_ac_fkey" so he doesnt know that the problem is the 2nd table "artcod". The DETAILS part of the error message is realy important for the user here.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 28 Feb 2011 08:42

To resolve the problem you can use the EPgError class like:

Code: Select all

uses PgError;

....

  try
    PgQuery.Delete;
  except
    on E: EPgError do
    begin
      ShowMEssage('Message: ' + e.Message+ ';' + #13 + 'SQL Status: ' + e.ErrorCode + #13+ 'Detail: ' + e.DetailMsg);
    end;

end;

dschuch
Posts: 75
Joined: Thu 05 Feb 2009 15:29
Location: Dresden

Post by dschuch » Mon 28 Feb 2011 09:44

working, thx

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Mon 28 Feb 2011 09:51

Hello,

It is good to see that this problem was solved. If any other questions come up, please contact us.

Post Reply