From: Daniele Varrazzo Date: Mon, 16 Mar 2020 06:54:40 +0000 (+1300) Subject: Added PQdescribePortal wrapper X-Git-Tag: 3.0.dev0~704 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3d178159fd170a76064c9dd120193f4922992b27;p=thirdparty%2Fpsycopg.git Added PQdescribePortal wrapper --- diff --git a/psycopg3/pq/pq_ctypes.py b/psycopg3/pq/pq_ctypes.py index 64032c09f..27f32f418 100644 --- a/psycopg3/pq/pq_ctypes.py +++ b/psycopg3/pq/pq_ctypes.py @@ -315,6 +315,16 @@ class PGconn: raise MemoryError("couldn't allocate PGresult") return PGresult(rv) + def describe_portal(self, name): + if not isinstance(name, bytes): + raise TypeError( + "'name' must be bytes, got %s instead" % type(name).__name__ + ) + rv = impl.PQdescribePortal(self.pgconn_ptr, name) + if rv is None: + raise MemoryError("couldn't allocate PGresult") + return PGresult(rv) + class PGresult: __slots__ = ("pgresult_ptr",) diff --git a/tests/pq/test_exec.py b/tests/pq/test_exec.py index 73d26db0e..16f099648 100644 --- a/tests/pq/test_exec.py +++ b/tests/pq/test_exec.py @@ -114,3 +114,18 @@ def test_exec_prepared_binary_out(pq, pgconn, fmt, out): ) assert res.status == pq.ExecStatus.PGRES_TUPLES_OK assert res.get_value(0, 0) == out + + +def test_describe_portal(pq, pgconn): + res = pgconn.exec_( + b""" + begin; + declare cur cursor for select * from generate_series(1,10) foo; + """ + ) + assert res.status == pq.ExecStatus.PGRES_COMMAND_OK, res.error_message + + res = pgconn.describe_portal(b"cur") + assert res.status == pq.ExecStatus.PGRES_COMMAND_OK, res.error_message + assert res.nfields == 1 + assert res.fname(0) == b"foo"