def _pq_fetch_tuples(self): with self._conn._lock: self._nfields = libpq.PQnfields(self._pgres) self._no_tuples = False description = [] casts = [] fast_parsers = [] for i in xrange(self._nfields): ftype = libpq.PQftype(self._pgres, i) fsize = libpq.PQfsize(self._pgres, i) fmod = libpq.PQfmod(self._pgres, i) if fmod > 0: fmod -= 4 # TODO: sizeof(int) if fsize == -1: if ftype == 1700: # NUMERIC isize = fmod >> 16 else: isize = fmod else: isize = fsize if ftype == 1700: prec = (fmod >> 16) & 0xFFFF scale = fmod & 0xFFFF else: prec = scale = None casts.append(self._get_cast(ftype)) description.append(Column( name=ffi.string(libpq.PQfname(self._pgres, i))\ .decode(self._conn._py_enc), type_code=ftype, display_size=None, internal_size=isize, precision=prec, scale=scale, null_ok=None, )) fast_parser = None if is_32bits: # disable all fast parsers to avoid portability problems pass elif ftype == 21 or ftype == 23: fast_parser = libpq.PQEgetint elif ftype == 20: fast_parser = libpq.PQEgetlong elif ftype == 700: fast_parser = libpq.PQEgetfloat elif ftype == 701: fast_parser = libpq.PQEgetdouble fast_parsers.append(fast_parser) self._description = tuple(description) self._casts = casts self._fast_parsers = fast_parsers
def _pq_fetch_tuples(self): with self._conn._lock: self._nfields = libpq.PQnfields(self._pgres) self._no_tuples = False description = [] casts = [] for i in xrange(self._nfields): ftype = libpq.PQftype(self._pgres, i) fsize = libpq.PQfsize(self._pgres, i) fmod = libpq.PQfmod(self._pgres, i) if fmod > 0: fmod -= 4 # TODO: sizeof(int) if fsize == -1: if ftype == 1700: # NUMERIC isize = fmod >> 16 else: isize = fmod else: isize = fsize if ftype == 1700: prec = (fmod >> 16) & 0xFFFF scale = fmod & 0xFFFF else: prec = scale = None casts.append(self._get_cast(ftype)) description.append(Column( name=ffi.string(libpq.PQfname(self._pgres, i)), type_code=ftype, display_size=None, internal_size=isize, precision=prec, scale=scale, null_ok=None, )) self._description = tuple(description) self._casts = casts