Access last_sqlstate from libpq

Поиск
Список
Период
Сортировка
От Daniel Frey
Тема Access last_sqlstate from libpq
Дата
Msg-id D0EA7D79-62C5-4733-B437-3A5C7C20746D@gmx.de
обсуждение исходный текст
Ответы Re: Access last_sqlstate from libpq  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Access last_sqlstate from libpq  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hi,

I am the author of a PostgreSQL C++ client library, taoPQ (https://github.com/taocpp/taopq), wrapping the C-API of
libpq.

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 );

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

* lo_* (large object functions)

Obviously, I can take the error message from PQerrorMessage and throw a generic runtime error - but it would be so much
nicerif I could use the SQLSTATE to throw the correct exception class and give users more information just like I do
forPGresult*. 

After some research, it appears that PGconn* does have a field called last_sqlstate - it just can't be accessed.
Are there any problems adding a simple accessor to libpq? Or is there some way to access it that I'm missing?

Regards,
Daniel




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

Предыдущее
От: Alexander Korotkov
Дата:
Сообщение: Re: postgres.h included from relcache.h - but removing it breaks pg_upgrade
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Access last_sqlstate from libpq