server and not yet completed.
.. autoattribute:: server_version
+ .. autoattribute:: backend_pid
+ .. autoattribute:: error_message
+
.. automethod:: get_parameters
.. autoattribute:: host
"""
return self.pgconn.server_version
+ @property
+ def backend_pid(self) -> int:
+ """
+ The process ID (PID) of the backend process handling this connection.
+ See :pq:`PQbackendPID`.
+ """
+ return self.pgconn.backend_pid
+
@property
def protocol_version(self) -> int:
"""
"""
return self.pgconn.protocol_version
+ @property
+ def error_message(self) -> str:
+ """
+ The error message most recently generated by an operation on the connection.
+ See :pq:`PQerrorMessage`.
+ """
+ return self._get_pgconn_attr("error_message")
+
def _get_pgconn_attr(self, name: str) -> str:
value: bytes = getattr(self.pgconn, name)
return value.decode(self._pyenc)
def test_protocol_version(self, conn):
assert conn.info.protocol_version >= 3
+
+ def test_error_message(self, conn):
+ assert conn.info.error_message == ""
+ with pytest.raises(psycopg3.ProgrammingError) as ex:
+ conn.execute("wat")
+
+ assert conn.info.error_message
+ assert str(ex.value) in conn.info.error_message
+ assert ex.value.diag.severity in conn.info.error_message
+
+ conn.close()
+ with pytest.raises(psycopg3.OperationalError):
+ conn.info.error_message
+
+ def test_backend_pid(self, conn):
+ assert conn.info.backend_pid
+ assert conn.info.backend_pid == conn.pgconn.backend_pid
+ conn.close()
+ with pytest.raises(psycopg3.OperationalError):
+ conn.info.backend_pid