From 4eef2d81b6bb12bd7e8d24bc26b07e724c14ba68 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 15 Mar 2020 00:59:36 +1300 Subject: [PATCH] Added PGconn.protocol_version --- psycopg3/_pq_ctypes.py | 4 ++++ psycopg3/pq_ctypes.py | 4 ++++ tests/test_pq.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/psycopg3/_pq_ctypes.py b/psycopg3/_pq_ctypes.py index 1feb246ac..da779cf40 100644 --- a/psycopg3/_pq_ctypes.py +++ b/psycopg3/_pq_ctypes.py @@ -141,6 +141,10 @@ PQparameterStatus = pq.PQparameterStatus PQparameterStatus.argtypes = [PGconn_ptr, c_char_p] PQparameterStatus.restype = c_char_p +PQprotocolVersion = pq.PQprotocolVersion +PQprotocolVersion.argtypes = [PGconn_ptr] +PQprotocolVersion.restype = c_int + PQerrorMessage = pq.PQerrorMessage PQerrorMessage.argtypes = [PGconn_ptr] PQerrorMessage.restype = c_char_p diff --git a/psycopg3/pq_ctypes.py b/psycopg3/pq_ctypes.py index 88c873f42..f7d3a42f3 100644 --- a/psycopg3/pq_ctypes.py +++ b/psycopg3/pq_ctypes.py @@ -173,6 +173,10 @@ class PGconn: rv = impl.PQparameterStatus(self.pgconn_ptr, self._encode(name)) return self._decode(rv) + @property + def protocol_version(self): + return impl.PQprotocolVersion(self.pgconn_ptr) + @property def error_message(self): return self._decode(impl.PQerrorMessage(self.pgconn_ptr)) diff --git a/tests/test_pq.py b/tests/test_pq.py index 5f1c22a8e..5e02b5403 100644 --- a/tests/test_pq.py +++ b/tests/test_pq.py @@ -179,3 +179,7 @@ def test_parameter_status(pq, dsn, tempenv): pgconn = pq.PGconn.connect(dsn) assert pgconn.parameter_status('application_name') == "psycopg3 tests" assert pgconn.parameter_status('wat') is None + + +def test_protocol_version(pgconn): + assert pgconn.protocol_version == 3 -- 2.47.3