예제 #1
0
    def _poll_setup_async(self):
        """Advance to the next state during an async connection setup

        If the connection is green, this is performed by the regular sync
        code so the queries are sent by conn_setup() while in
        CONN_STATUS_READY state.

        """
        if self.status == consts.STATUS_CONNECTING:
            util.pq_set_non_blocking(self._pgconn, 1, True)

            self._equote = self._get_equote()
            self._get_encoding()
            self._cancel = libpq.PQgetCancel(self._pgconn)
            if self._cancel is None:
                raise exceptions.OperationalError("can't get cancellation key")

            self._autocommit = True

            # If the current datestyle is not compatible (not ISO) then
            # force it to ISO
            datestyle = libpq.PQparameterStatus(self._pgconn, 'DateStyle')
            if not datestyle or not datestyle.startswith('ISO'):
                self.status = consts.STATUS_DATESTYLE

                if libpq.PQsendQuery(self._pgconn, "SET DATESTYLE TO 'ISO'"):
                    self._async_status = consts.ASYNC_WRITE
                    return consts.POLL_WRITE
                else:
                    raise self._create_exception()

            self.status = consts.STATUS_READY
            return consts.POLL_OK

        if self.status == consts.STATUS_DATESTYLE:
            res = self._poll_query()
            if res != consts.POLL_OK:
                return res

            pgres = util.pq_get_last_result(self._pgconn)
            if not pgres or \
                libpq.PQresultStatus(pgres) != libpq.PGRES_COMMAND_OK:
                raise exceptions.OperationalError("can't set datetyle to ISO")
            libpq.PQclear(pgres)

            self.status = consts.STATUS_READY
            return consts.POLL_OK

        return consts.POLL_ERROR
예제 #2
0
    def _setup(self):
        self._equote = self._get_equote()
        self._get_encoding()

        self._cancel = libpq.PQgetCancel(self._pgconn)
        if self._cancel is None:
            raise exceptions.OperationalError("can't get cancellation key")

        with self._lock:
            # If the current datestyle is not compatible (not ISO) then
            # force it to ISO
            datestyle = libpq.PQparameterStatus(self._pgconn, 'DateStyle')
            if not datestyle or not datestyle.startswith('ISO'):
                self.status = consts.STATUS_DATESTYLE
                self._set_guc('datestyle', 'ISO')

            self._closed = False
예제 #3
0
 def _get_equote(self):
     ret = libpq.PQparameterStatus(self._pgconn,
                                   'standard_conforming_strings')
     return ret and ret == 'off'
예제 #4
0
 def get_parameter_status(self, parameter):
     return libpq.PQparameterStatus(self._pgconn, parameter)