Getting error codes for failed queries? - Mailing list pgsql-general

From Alejandro Forero Cuervo
Subject Getting error codes for failed queries?
Date
Msg-id 20031015165507.GA541@bachue.com
Whole thread Raw
Responses Re: Getting error codes for failed queries?
List pgsql-general
Hello.

I'm  new to  PostgreSQL and  I'm using  it for  some project.   I
am  currently  creating an  entity  engine  that provides  a  web
interface, which is  oriented towards end users,  to the database
based on some  enriched description of the tables  (from which it
also generates the SQL code to create them).

My application  connects to  the database using  the socket-level
frontend/backend protocol rather than providing a wrapper around
the libpq library.

When an error takes places executing a query, all I get is string
describing the error, such as ``ERROR:  Cannot insert a duplicate
key  into unique  index locations_name_key''.   However, I  can't
pass  this error  description back  to the  end-users: I have  to
translate it  into something  meaningful for them  (for instance,
something that refers to the fields they are seeing in their HTML
forms and something in the language they selected).

Currently, when  an error  takes place,  I send  multiple queries
back to the database trying to  detect what could be the cause(s)
of the error.  This seems wrong as  I can't know in advance, in a
maintainable way, all the possible causes for errors.  It is also
slow as multiple  (ideally redundant) queries have to  be sent to
the database.

I could also  parse the error string and try  to detect what went
wrong based  on it, but  I'd rather  stay away from  that option,
which  doesn't look  very  maintainable.  Or  should  I do  that?
Do  those  strings get  translated  to  different languages,  for
instance?

What would experienced PostgreSQL users suggest I do?

Alejo.
http://bachue.com/alejo

--
The mere formulation of a problem is far more essential than its solution.
      -- Albert Einstein.

$0='!/sfldbi!yjoV0msfQ!sfiupob!utvK'x44;print map{("\e[7m \e[0m",chr ord
(chop$0)-1)[$_].("\n")[++$i%77]}split//,unpack'B*',pack'H*',($F='F'x19).
"F0F3E0607879CC1E0F0F339F3FF399C666733333CCF87F99E6133999999E67CFFCCF3".
"219CC1CCC033E7E660198CCE4E66798303873CCE60F3387$F"#Don't you love Perl?

Attachment

pgsql-general by date:

Previous
From: Dennis Gearon
Date:
Subject: Re: SET within a function?
Next
From: Tom Lane
Date:
Subject: Re: VACUUM degrades performance significantly. Database becomes unusable!