From 6ba1756bfc26d2711a756ac60e0ca7da9b648974 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 23 Apr 2021 01:46:40 +0100 Subject: [PATCH] Separate C and Python pgresult_ptr attribute names The distinction is not used yet. However, let's do that for consistency with pgconn_ptr. --- psycopg3_c/psycopg3_c/_psycopg3/transform.pyx | 6 +- psycopg3_c/psycopg3_c/pq.pxd | 2 +- psycopg3_c/psycopg3_c/pq/pgconn.pyx | 2 +- psycopg3_c/psycopg3_c/pq/pgresult.pyx | 58 +++++++++---------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/psycopg3_c/psycopg3_c/_psycopg3/transform.pyx b/psycopg3_c/psycopg3_c/_psycopg3/transform.pyx index dc6956ac0..5635d6ca5 100644 --- a/psycopg3_c/psycopg3_c/_psycopg3/transform.pyx +++ b/psycopg3_c/psycopg3_c/_psycopg3/transform.pyx @@ -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 = 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 = res diff --git a/psycopg3_c/psycopg3_c/pq.pxd b/psycopg3_c/psycopg3_c/pq.pxd index 49dca7cb5..55aeb63cb 100644 --- a/psycopg3_c/psycopg3_c/pq.pxd +++ b/psycopg3_c/psycopg3_c/pq.pxd @@ -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) diff --git a/psycopg3_c/psycopg3_c/pq/pgconn.pyx b/psycopg3_c/psycopg3_c/pq/pgconn.pyx index f6b7a21a0..91d937f2d 100644 --- a/psycopg3_c/psycopg3_c/pq/pgconn.pyx +++ b/psycopg3_c/psycopg3_c/pq/pgconn.pyx @@ -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( diff --git a/psycopg3_c/psycopg3_c/pq/pgresult.pyx b/psycopg3_c/psycopg3_c/pq/pgresult.pyx index 196b1ba92..e05c203d5 100644 --- a/psycopg3_c/psycopg3_c/pq/pgresult.pyx +++ b/psycopg3_c/psycopg3_c/pq/pgresult.pyx @@ -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 self.pgresult_ptr + if self._pgresult_ptr: + return 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") -- 2.47.2