-include "pq/pq_cython.pyx"
include "types/numeric.pyx"
include "types/text.pyx"
include "transform.pyx"
if not impl or impl == "c":
try:
# TODO: extension module not recognised by mypy?
- from psycopg3 import _psycopg3 # type: ignore
+ from . import pq_cython # type: ignore
except Exception as e:
if not impl:
logger.debug(f"C pq wrapper not available: %s", e)
f"requested pq implementation '{impl}' not available"
) from e
else:
- __impl__ = _psycopg3.__impl__
- version = _psycopg3.version
- PGconn = _psycopg3.PGconn
- PGresult = _psycopg3.PGresult
- Conninfo = _psycopg3.Conninfo
- Escaping = _psycopg3.Escaping
+ __impl__ = pq_cython.__impl__
+ version = pq_cython.version
+ PGconn = pq_cython.PGconn
+ PGresult = pq_cython.PGresult
+ Conninfo = pq_cython.Conninfo
+ Escaping = pq_cython.Escaping
return
if not impl or impl == "ctypes":
--- /dev/null
+from psycopg3.pq cimport libpq as impl
+
+ctypedef char *(*conn_bytes_f) (const impl.PGconn *)
+ctypedef int(*conn_int_f) (const impl.PGconn *)
+
+
+cdef class PGconn:
+ cdef impl.PGconn* pgconn_ptr
+
+ @staticmethod
+ cdef PGconn _from_ptr(impl.PGconn *ptr)
+
+ cdef int _ensure_pgconn(self) except 0
+ cdef char *_call_bytes(self, conn_bytes_f func) except NULL
+ cdef int _call_int(self, conn_int_f func) except -1
+
+
+cdef class PGresult:
+ cdef impl.PGresult* pgresult_ptr
+
+ @staticmethod
+ cdef PGresult _from_ptr(impl.PGresult *ptr)
from cpython.mem cimport PyMem_Malloc, PyMem_Free
from psycopg3.pq cimport libpq as impl
+from psycopg3.pq.libpq cimport Oid
from psycopg3.errors import OperationalError
from psycopg3.pq.misc import error_message, ConninfoOption, PQerror
def version():
return impl.PQlibVersion()
-ctypedef unsigned int Oid;
-ctypedef char *(*conn_bytes_f) (const impl.PGconn *)
-ctypedef int(*conn_int_f) (const impl.PGconn *)
cdef class PGconn:
- cdef impl.PGconn* pgconn_ptr
-
@staticmethod
cdef PGconn _from_ptr(impl.PGconn *ptr):
cdef PGconn rv = PGconn.__new__(PGconn)
cdef class PGresult:
- cdef impl.PGresult* pgresult_ptr
-
def __cinit__(self):
self.pgresult_ptr = NULL
from typing import Any, Dict, Iterable, List, Optional, Tuple
from psycopg3.pq cimport libpq
+from psycopg3.pq.pq_cython cimport PGresult
from psycopg3 import errors as e
-# from psycopg3.pq.enum import Format
+from psycopg3.pq.enums import Format
# from psycopg3.types.oids import builtins, INVALID_OID
TEXT_OID = 25
for i, (oid, fmt) in enumerate(types):
loader = self._set_loader(i, oid, fmt)
- cdef void _set_loader(self, int col, Oid oid, int fmt):
+ cdef void _set_loader(self, int col, libpq.Oid oid, int fmt):
cdef RowLoader *loader = self._row_loaders + col
pyloader = self.get_load_function(oid, fmt)
includedir = out.stdout.strip().decode("utf8")
- ext = Extension(
+ pgext = Extension(
"psycopg3._psycopg3",
["psycopg3/_psycopg3.pyx"],
libraries=["pq"],
include_dirs=[includedir],
)
+ pqext = Extension(
+ "psycopg3.pq.pq_cython",
+ ["psycopg3/pq/pq_cython.pyx"],
+ libraries=["pq"],
+ include_dirs=[includedir],
+ )
self.distribution.ext_modules = cythonize(
- [ext],
+ [pgext, pqext],
language_level=3,
# annotate=True, # enable to get an html view of the C module
)