Re: Access last_sqlstate from libpq

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Access last_sqlstate from libpq
Дата
Msg-id 1421674.1631932178@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Access last_sqlstate from libpq  (Daniel Frey <d.frey@gmx.de>)
Список pgsql-hackers
Daniel Frey <d.frey@gmx.de> writes:
> In case of an error when I received a PGresult*, I can access the SQLSTATE by calling

>    PGresult* pgresult = ...;
>    const char* sqlstate = PQresultErrorField( pgresult, PG_DIAG_SQLSTATE );

Right ...

> However, this is not possible in a couple of other cases where I don't have a PGresult*, only the PGconn* is
available:
> * PQconnectdb (and variants)
> * PQputCopyData
> * PQputCopyEnd
> * PQgetCopyData

In these cases, any error you might get is probably from libpq itself,
not from the server.  libpq does not generate SQLSTATEs for its errors,
so it's likely that last_sqlstate is not relevant at all.

(Getting libpq to assign SQLSTATEs to its errors has been on the to-do
list for a couple of decades.  I'm not holding my breath for somebody
to undertake that.)

> Are there any problems adding a simple accessor to libpq?

I would be strongly against that unless somebody first did the
legwork to ensure it was meaningful.

            regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Michael Paquier
Дата:
Сообщение: Re: improve pg_receivewal code
Следующее
От: Neil Chen
Дата:
Сообщение: Re: psql: \dl+ to list large objects privileges