]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Added PQresult info functions
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 20 Mar 2020 13:30:27 +0000 (02:30 +1300)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 20 Mar 2020 13:30:43 +0000 (02:30 +1300)
psycopg3/pq/_pq_ctypes.py
psycopg3/pq/pq_ctypes.py
tests/pq/test_pgresult.py

index 3e6086526e293dbb38f9340d629833b72ce37875..858f78cb4f91d8dac406ab60178868831cd48bd7 100644 (file)
@@ -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
 
index 1d158fc87f0f019d064c3702c4655146db6daed2..e6822796dd3bffd59a80d649d3bc16482580feaa 100644 (file)
@@ -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"
index e151d87992bddc2b423a50bb04ddaf4035979719..6bb55e2a552005a1ba4754db2c62d47718d166ab 100644 (file)
@@ -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