def _build_row(self): row_num = self._rownumber # Create the row if self.row_factory: row = self.row_factory(self) is_tuple = False else: row = [None] * self._nfields is_tuple = True # Fill it n = self._nfields for i in xrange(n): if libpq.PQgetisnull(self._pgres, row_num, i): row[i] = None else: fast_parser = self._fast_parsers[i] if fast_parser: row[i] = fast_parser(self._pgres, row_num, i) else: length = libpq.PQgetlength(self._pgres, row_num, i) val = ffi.buffer(libpq.PQgetvalue(self._pgres, row_num, i), length)[:] row[i] = typecasts.typecast(self._casts[i], val, length, self) self._rownumber += 1 if is_tuple: return tuple(row) return row
def _get_guc(self, name): """Return the value of a configuration parameter.""" with self._lock: query = 'SHOW %s' % name if _green_callback: pgres = self._execute_green(query) else: pgres = libpq.PQexec(self._pgconn, query) if not pgres or libpq.PQresultStatus(pgres) != libpq.PGRES_TUPLES_OK: raise exceptions.OperationalError("can't fetch %s" % name) rv = ffi.string(libpq.PQgetvalue(pgres, 0, 0)) libpq.PQclear(pgres) return rv