From: Daniele Varrazzo Date: Fri, 20 Mar 2020 13:30:27 +0000 (+1300) Subject: Added PQresult info functions X-Git-Tag: 3.0.dev0~691 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3b9823fd45451597a5b8f477fc09610b1ccabbfc;p=thirdparty%2Fpsycopg.git Added PQresult info functions --- diff --git a/psycopg3/pq/_pq_ctypes.py b/psycopg3/pq/_pq_ctypes.py index 3e6086526..858f78cb4 100644 --- a/psycopg3/pq/_pq_ctypes.py +++ b/psycopg3/pq/_pq_ctypes.py @@ -314,6 +314,20 @@ PQparamtype.restype = Oid # PQprint: pretty useless +# 33.3.3. Retrieving Other Result Information + +PQcmdStatus = pq.PQcmdStatus +PQcmdStatus.argtypes = [PGresult_ptr] +PQcmdStatus.restype = c_char_p + +PQcmdTuples = pq.PQcmdTuples +PQcmdTuples.argtypes = [PGresult_ptr] +PQcmdTuples.restype = c_char_p + +PQoidValue = pq.PQoidValue +PQoidValue.argtypes = [PGresult_ptr] +PQoidValue.restype = Oid + # 33.4. Asynchronous Command Processing diff --git a/psycopg3/pq/pq_ctypes.py b/psycopg3/pq/pq_ctypes.py index 1d158fc87..e6822796d 100644 --- a/psycopg3/pq/pq_ctypes.py +++ b/psycopg3/pq/pq_ctypes.py @@ -446,6 +446,20 @@ class PGresult: def param_type(self, param_number): return impl.PQparamtype(self.pgresult_ptr, param_number) + @property + def command_status(self): + return impl.PQcmdStatus(self.pgresult_ptr) + + @property + def command_tuples(self): + rv = impl.PQcmdTuples(self.pgresult_ptr) + if rv: + return int(rv) + + @property + def oid_value(self): + return impl.PQoidValue(self.pgresult_ptr) + ConninfoOption = namedtuple( "ConninfoOption", "keyword envvar compiled val label dispatcher dispsize" diff --git a/tests/pq/test_pgresult.py b/tests/pq/test_pgresult.py index e151d8799..6bb55e2a5 100644 --- a/tests/pq/test_pgresult.py +++ b/tests/pq/test_pgresult.py @@ -123,3 +123,22 @@ def test_nparams_types(pq, pgconn): assert res.nparams == 2 assert res.param_type(0) == 23 assert res.param_type(1) == 25 + + +def test_command_status(pq, pgconn): + res = pgconn.exec_(b"select 1") + assert res.command_status == b"SELECT 1" + res = pgconn.exec_(b"set timezone to utf8") + assert res.command_status == b"SET" + + +def test_command_tuples(pq, pgconn): + res = pgconn.exec_(b"select * from generate_series(1, 10)") + assert res.command_tuples == 10 + res = pgconn.exec_(b"set timezone to utf8") + assert res.command_tuples is None + + +def test_oid_value(pq, pgconn): + res = pgconn.exec_(b"select 1") + assert res.oid_value == 0