pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
libpq and error codes
2+ messages / 2 participants
[nested] [flat]

* libpq and error codes
@ 2007-08-24 14:37  Dave Williss <dwilliss@microimages.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Dave Williss @ 2007-08-24 14:37 UTC (permalink / raw)
  To: pgsql-interfaces

I can't seem to find a reliable way to determine if the error from a 
call to PQconnectdb is due to an invalid username/password.  I can call 
PQstatus and it tells me CONNECTION_BAD, which I'd expect, and then 
PQerrorMessage gives me a plain text message that explains the reason, but
error messages can be localized.  A different version of PostgreSQL may 
decide to change the wording, so just doing a string comparison on the 
error message won't cut it.

What I need is a nice, numeric error code that I can compare to a known 
value that means invalid password. But there doesn't seem to be any 
function to do that. Am I just being blind? 

The reason I need this is that in our software, if the user tries to 
open a connection to a database and gets an authorization error of some 
kind, we pop up a username/password dialog and let them try again.  But 
if it's due to any other kind of problem (server down, etc), we give 
them the error message directly.

Dave Williss



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: libpq and error codes
@ 2007-08-24 16:41  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Dave Williss <dwilliss@microimages.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2007-08-24 16:41 UTC (permalink / raw)
  To: Dave Williss <dwilliss@microimages.com>; +Cc: pgsql-interfaces

Dave Williss <dwilliss@microimages.com> writes:
> I can't seem to find a reliable way to determine if the error from a 
> call to PQconnectdb is due to an invalid username/password.  I can call 
> PQstatus and it tells me CONNECTION_BAD, which I'd expect, and then 
> PQerrorMessage gives me a plain text message that explains the reason, but
> error messages can be localized.  A different version of PostgreSQL may 
> decide to change the wording, so just doing a string comparison on the 
> error message won't cut it.

Actually, in current releases you can --- the bad-password message is
deliberately not localized so that this is possible.  Compare to the
PQnoPasswordSupplied #define provided by libpq-fe.h.  (You can find
examples of this if you look into the source code for, for example,
psql.)

Of course, that pretty much sucks.  As of 8.3 there will be a status
function PQconnectionUsedPassword() to provide a cleaner API for
deciding whether you should issue a password prompt.

The more general idea that we should associate SQLStates with each
distinct error report inside libpq is still far off, I'm afraid.
It's a big job and no one has shown interest in tackling it.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-08-24 16:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-08-24 14:37 libpq and error codes Dave Williss <dwilliss@microimages.com>
2007-08-24 16:41 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox