]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Added PQdescribePortal wrapper
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 16 Mar 2020 06:54:40 +0000 (19:54 +1300)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 16 Mar 2020 09:06:05 +0000 (22:06 +1300)
psycopg3/pq/pq_ctypes.py
tests/pq/test_exec.py

index 64032c09fd9cd962f6aa045c503e1840823f13e8..27f32f41829f77974c7526081886b3168dafb64c 100644 (file)
@@ -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",)
index 73d26db0e4ff4fa1ff3bf86e4b9ab91becff52bf..16f09964887487113d3968070a605d902cb4bcf4 100644 (file)
@@ -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"