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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Hello World <worldanizer(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: libpq: How to get the error code after a failed PGconn connection
Date: 2014-04-29 22:18:12
Message-ID: 28833.1398809892@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello World <worldanizer(at)gmail(dot)com> writes:
> 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.

1. This question is not really material for the -hackers list.

2. No, I'm afraid. libpq does not currently assign SQLSTATE error codes
to errors it detects internally, so even if there were an API for this,
it would fail to return anything in a lot of cases. Fixing that is on
the TODO list, but it's been there for a long time, so don't hold your
breath ...

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2014-04-29 22:20:23 Re: Considerer Harmful Considered Harmful
Previous Message Stephen Frost 2014-04-29 21:33:11 Re: pg_dump --pretty-print-views