From: Daniele Varrazzo Date: Thu, 19 Mar 2020 09:03:14 +0000 (+1300) Subject: Added PGconn.make_empty_result() X-Git-Tag: 3.0.dev0~696 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=78378453ae82beaa61ca78db9f7af52a7e2a36d8;p=thirdparty%2Fpsycopg.git Added PGconn.make_empty_result() --- diff --git a/psycopg3/pq/_pq_ctypes.py b/psycopg3/pq/_pq_ctypes.py index 98b3b7442..3e6086526 100644 --- a/psycopg3/pq/_pq_ctypes.py +++ b/psycopg3/pq/_pq_ctypes.py @@ -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 diff --git a/psycopg3/pq/pq_ctypes.py b/psycopg3/pq/pq_ctypes.py index 7e4549abd..3ae879638 100644 --- a/psycopg3/pq/pq_ctypes.py +++ b/psycopg3/pq/pq_ctypes.py @@ -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",) diff --git a/tests/pq/test_pgconn.py b/tests/pq/test_pgconn.py index 504d2d23c..ac0eb261e 100644 --- a/tests/pq/test_pgconn.py +++ b/tests/pq/test_pgconn.py @@ -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