libpq: How to get the error code after a failed PGconn connection

From: Hello World <worldanizer(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: libpq: How to get the error code after a failed PGconn connection
Date: 2014-04-29 18:19:03
Message-ID: CAB8jeLmtrsH8Uo_VZnKSP_bThty37webO5igqr-mX=w3sGJxzA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Given the following code.

PGconn* const conn=PQconnectdbParams(keywords, values, false);
if(! conn || PQstatus(conn)!=CONNECTION_OK){ /* error code? */ }

- In case of a failed connection is there a way to get the error code to be
able to distinguish between a (e.g.) bad password and the server being down.

(I know I can get the error message, but I want to be able to react to the
cause of the error according to its cause, plus the error message is
localized so I can't even scan that for keywords such as "permission
denied").

ps. I've looked at how psql does it, and it seems it just prints the error
message and exists.

ps. I've tried to take a look at the source but it seems it just sets the
status to CONNECTION_BAD no matter the cause of error, then sets a specific
error message.

Any help appreciated.

Thanks.

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Greg Stark 2014-04-29 18:25:23 Re: pg_get_viewdefs() indentation considered harmful
Previous Message Nikhil Deshpande 2014-04-29 18:14:32 Fix initdb for path with whitespace and at char