]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Added PGconn.make_empty_result()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 19 Mar 2020 09:03:14 +0000 (22:03 +1300)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 19 Mar 2020 09:33:48 +0000 (22:33 +1300)
psycopg3/pq/_pq_ctypes.py
psycopg3/pq/pq_ctypes.py
tests/pq/test_pgconn.py

index 98b3b744290bf846767a8cfcf06c84034d5d5abd..3e6086526e293dbb38f9340d629833b72ce37875 100644 (file)
@@ -354,3 +354,7 @@ PQflush.restype == c_int
 PQfreemem = pq.PQfreemem
 PQfreemem.argtypes = [c_void_p]
 PQfreemem.restype = None
+
+PQmakeEmptyPGresult = pq.PQmakeEmptyPGresult
+PQmakeEmptyPGresult.argtypes = [PGconn_ptr, c_int]
+PQmakeEmptyPGresult.restype = PGresult_ptr
index 7e4549abd1dca07dcf4c5b19a7e7d512277f9904..3ae87963857f10dc32a86621a5520bf1b4fac44a 100644 (file)
@@ -364,6 +364,12 @@ class PGconn:
             raise PQerror(f"flushing failed: {error_message(self)}")
         return rv
 
+    def make_empty_result(self, exec_status):
+        rv = impl.PQmakeEmptyPGresult(self.pgconn_ptr, exec_status)
+        if not rv:
+            raise MemoryError("couldn't allocate empty PGresult")
+        return PGresult(rv)
+
 
 class PGresult:
     __slots__ = ("pgresult_ptr",)
index 504d2d23c9f64f0b8ce06c21f789ed5455063daf..ac0eb261e027de42b4ae6cb02e9611048dc7abcd 100644 (file)
@@ -209,3 +209,10 @@ def test_ssl_in_use(pgconn):
             # 'prefer' may still connect without ssl
             # but maybe unlikely in the tests environment?
             assert pgconn.ssl_in_use
+
+
+def test_make_empty_result(pq, pgconn):
+    pgconn.exec_(b"wat")
+    res = pgconn.make_empty_result(pq.ExecStatus.PGRES_FATAL_ERROR)
+    assert res.status == pq.ExecStatus.PGRES_FATAL_ERROR
+    assert b"wat" in res.error_message