Getting the SQLSTATE after a failed connection - Mailing list pgsql-hackers

From Daniele Varrazzo
Subject Getting the SQLSTATE after a failed connection
Date
Msg-id CA+mi_8ZRi-NJsOw5SFUMXACLm-OFoS+DeRV3_5m7RgHfPXx1gg@mail.gmail.com
Whole thread Raw
Responses Re: Getting the SQLSTATE after a failed connection
Re: Getting the SQLSTATE after a failed connection
List pgsql-hackers
Hello,

in ticket <https://github.com/psycopg/psycopg/issues/1188> an user
showed that, upon a failed connection attempt because of a bad
password, the server sends a SQLSTATE 28P01 message. However psycopg
cannot raise the expected `InvalidPassword` exception, because the
only way to get the SQLSTATE seems to be from a PGresult via
PQresultErrorField and I fail to see any API call to get the info from
a PGconn.

Using `PQmakeEmptyPGresult` didn't help either: PQresultErrorField
reports no data about the error.

Browsing the code, it seems that PqMsg_CommandComplete is only handled
in isBusy/getResult. There is a promising `last_sqlstate` in the
structure but it seems only used internally and not exposed.

Is there any way to get the last SQLSTATE from the connection object
or is that information lost?

Thank you very much

-- Daniele



pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: anonymous unions (C11)
Next
From: Fujii Masao
Date:
Subject: Re: Fix lag columns in pg_stat_replication not advancing when replay LSN stalls