]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Separate C and Python pgresult_ptr attribute names
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 23 Apr 2021 00:46:40 +0000 (01:46 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Fri, 23 Apr 2021 00:46:40 +0000 (01:46 +0100)
The distinction is not used yet. However, let's do that for consistency
with pgconn_ptr.

psycopg3_c/psycopg3_c/_psycopg3/transform.pyx
psycopg3_c/psycopg3_c/pq.pxd
psycopg3_c/psycopg3_c/pq/pgconn.pyx
psycopg3_c/psycopg3_c/pq/pgresult.pyx

index dc6956ac0f9b180939f3cba2810614246da0f038..5635d6ca514871f573039b102eb7e3e1fbaeb314 100644 (file)
@@ -107,7 +107,7 @@ cdef class Transformer:
                 self._row_loaders = []
             return
 
-        cdef libpq.PGresult *res = self._pgresult.pgresult_ptr
+        cdef libpq.PGresult *res = self._pgresult._pgresult_ptr
         self._nfields = libpq.PQnfields(res)
         self._ntuples = libpq.PQntuples(res)
 
@@ -283,7 +283,7 @@ cdef class Transformer:
                 f"rows must be included between 0 and {self._ntuples}"
             )
 
-        cdef libpq.PGresult *res = self._pgresult.pgresult_ptr
+        cdef libpq.PGresult *res = self._pgresult._pgresult_ptr
         # cheeky access to the internal PGresult structure
         cdef pg_result_int *ires = <pg_result_int*>res
 
@@ -352,7 +352,7 @@ cdef class Transformer:
         if not 0 <= row < self._ntuples:
             return None
 
-        cdef libpq.PGresult *res = self._pgresult.pgresult_ptr
+        cdef libpq.PGresult *res = self._pgresult._pgresult_ptr
         # cheeky access to the internal PGresult structure
         cdef pg_result_int *ires = <pg_result_int*>res
 
index 49dca7cb59de5b9c4e0a859331898d616dcde042..55aeb63cbd8540ae463e2333db563a3d9b3debf0 100644 (file)
@@ -19,7 +19,7 @@ cdef class PGconn:
 
 
 cdef class PGresult:
-    cdef libpq.PGresult* pgresult_ptr
+    cdef libpq.PGresult* _pgresult_ptr
 
     @staticmethod
     cdef PGresult _from_ptr(libpq.PGresult *ptr)
index f6b7a21a0f47da5e67436b8da4bfc7b182967090..91d937f2d7e890b6437c6db5e3ec4898227cbc43 100644 (file)
@@ -535,7 +535,7 @@ cdef void notice_receiver(void *arg, const libpq.PGresult *res_ptr) with gil:
     except Exception as e:
         logger.exception("error in notice receiver: %s", e)
 
-    res.pgresult_ptr = NULL  # avoid destroying the pgresult_ptr
+    res._pgresult_ptr = NULL  # avoid destroying the pgresult_ptr
 
 
 cdef (int, libpq.Oid *, char * const*, int *, int *) _query_params_args(
index 196b1ba92a80e9e77b98c66b1b5da72a370b1aca..e05c203d59cae87d03ef6f1dd6bc213dfa84cc6b 100644 (file)
@@ -14,12 +14,12 @@ from psycopg3.pq._enums import ExecStatus
 @cython.freelist(8)
 cdef class PGresult:
     def __cinit__(self):
-        self.pgresult_ptr = NULL
+        self._pgresult_ptr = NULL
 
     @staticmethod
     cdef PGresult _from_ptr(libpq.PGresult *ptr):
         cdef PGresult rv = PGresult.__new__(PGresult)
-        rv.pgresult_ptr = ptr
+        rv._pgresult_ptr = ptr
         return rv
 
     def __dealloc__(self) -> None:
@@ -31,27 +31,27 @@ cdef class PGresult:
         return f"<{cls} [{status.name}] at 0x{id(self):x}>"
 
     def clear(self) -> None:
-        if self.pgresult_ptr is not NULL:
-            libpq.PQclear(self.pgresult_ptr)
-            self.pgresult_ptr = NULL
+        if self._pgresult_ptr is not NULL:
+            libpq.PQclear(self._pgresult_ptr)
+            self._pgresult_ptr = NULL
 
     @property
     def pgresult_ptr(self) -> Optional[int]:
-        if self.pgresult_ptr:
-            return <long><void *>self.pgresult_ptr
+        if self._pgresult_ptr:
+            return <long><void *>self._pgresult_ptr
         else:
             return None
 
     @property
     def status(self) -> int:
-        return libpq.PQresultStatus(self.pgresult_ptr)
+        return libpq.PQresultStatus(self._pgresult_ptr)
 
     @property
     def error_message(self) -> bytes:
-        return libpq.PQresultErrorMessage(self.pgresult_ptr)
+        return libpq.PQresultErrorMessage(self._pgresult_ptr)
 
     def error_field(self, int fieldcode) -> Optional[bytes]:
-        cdef char * rv = libpq.PQresultErrorField(self.pgresult_ptr, fieldcode)
+        cdef char * rv = libpq.PQresultErrorField(self._pgresult_ptr, fieldcode)
         if rv is not NULL:
             return rv
         else:
@@ -59,66 +59,66 @@ cdef class PGresult:
 
     @property
     def ntuples(self) -> int:
-        return libpq.PQntuples(self.pgresult_ptr)
+        return libpq.PQntuples(self._pgresult_ptr)
 
     @property
     def nfields(self) -> int:
-        return libpq.PQnfields(self.pgresult_ptr)
+        return libpq.PQnfields(self._pgresult_ptr)
 
     def fname(self, int column_number) -> Optional[bytes]:
-        cdef char *rv = libpq.PQfname(self.pgresult_ptr, column_number)
+        cdef char *rv = libpq.PQfname(self._pgresult_ptr, column_number)
         if rv is not NULL:
             return rv
         else:
             return None
 
     def ftable(self, int column_number) -> int:
-        return libpq.PQftable(self.pgresult_ptr, column_number)
+        return libpq.PQftable(self._pgresult_ptr, column_number)
 
     def ftablecol(self, int column_number) -> int:
-        return libpq.PQftablecol(self.pgresult_ptr, column_number)
+        return libpq.PQftablecol(self._pgresult_ptr, column_number)
 
     def fformat(self, int column_number) -> int:
-        return libpq.PQfformat(self.pgresult_ptr, column_number)
+        return libpq.PQfformat(self._pgresult_ptr, column_number)
 
     def ftype(self, int column_number) -> int:
-        return libpq.PQftype(self.pgresult_ptr, column_number)
+        return libpq.PQftype(self._pgresult_ptr, column_number)
 
     def fmod(self, int column_number) -> int:
-        return libpq.PQfmod(self.pgresult_ptr, column_number)
+        return libpq.PQfmod(self._pgresult_ptr, column_number)
 
     def fsize(self, int column_number) -> int:
-        return libpq.PQfsize(self.pgresult_ptr, column_number)
+        return libpq.PQfsize(self._pgresult_ptr, column_number)
 
     @property
     def binary_tuples(self) -> int:
-        return libpq.PQbinaryTuples(self.pgresult_ptr)
+        return libpq.PQbinaryTuples(self._pgresult_ptr)
 
     def get_value(self, int row_number, int column_number) -> Optional[bytes]:
         cdef int crow = row_number
         cdef int ccol = column_number
-        cdef int length = libpq.PQgetlength(self.pgresult_ptr, crow, ccol)
+        cdef int length = libpq.PQgetlength(self._pgresult_ptr, crow, ccol)
         cdef char *v
         if length:
-            v = libpq.PQgetvalue(self.pgresult_ptr, crow, ccol)
+            v = libpq.PQgetvalue(self._pgresult_ptr, crow, ccol)
             # TODO: avoid copy
             return v[:length]
         else:
-            if libpq.PQgetisnull(self.pgresult_ptr, crow, ccol):
+            if libpq.PQgetisnull(self._pgresult_ptr, crow, ccol):
                 return None
             else:
                 return b""
 
     @property
     def nparams(self) -> int:
-        return libpq.PQnparams(self.pgresult_ptr)
+        return libpq.PQnparams(self._pgresult_ptr)
 
     def param_type(self, int param_number) -> int:
-        return libpq.PQparamtype(self.pgresult_ptr, param_number)
+        return libpq.PQparamtype(self._pgresult_ptr, param_number)
 
     @property
     def command_status(self) -> Optional[bytes]:
-        cdef char *rv = libpq.PQcmdStatus(self.pgresult_ptr)
+        cdef char *rv = libpq.PQcmdStatus(self._pgresult_ptr)
         if rv is not NULL:
             return rv
         else:
@@ -126,7 +126,7 @@ cdef class PGresult:
 
     @property
     def command_tuples(self) -> Optional[int]:
-        cdef char *rv = libpq.PQcmdTuples(self.pgresult_ptr)
+        cdef char *rv = libpq.PQcmdTuples(self._pgresult_ptr)
         if rv is NULL:
             return None
         cdef bytes brv = rv
@@ -134,7 +134,7 @@ cdef class PGresult:
 
     @property
     def oid_value(self) -> int:
-        return libpq.PQoidValue(self.pgresult_ptr)
+        return libpq.PQoidValue(self._pgresult_ptr)
 
     def set_attributes(self, descriptions: List[PGresAttDesc]):
         cdef int num = len(descriptions)
@@ -151,7 +151,7 @@ cdef class PGresult:
             attrs[i].typlen = descr.typlen
             attrs[i].atttypmod = descr.atttypmod
 
-        cdef int res = libpq.PQsetResultAttrs(self.pgresult_ptr, num, attrs)
+        cdef int res = libpq.PQsetResultAttrs(self._pgresult_ptr, num, attrs)
         PyMem_Free(attrs)
         if (res == 0):
             raise e.OperationalError("PQsetResultAttrs failed")