当前位置: 首页>>代码示例>>Python>>正文


Python RequestMessage.new方法代码示例

本文整理汇总了Python中pyhdb.protocol.message.RequestMessage.new方法的典型用法代码示例。如果您正苦于以下问题:Python RequestMessage.new方法的具体用法?Python RequestMessage.new怎么用?Python RequestMessage.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyhdb.protocol.message.RequestMessage的用法示例。


在下文中一共展示了RequestMessage.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_request_message_use_last_session_id

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def test_request_message_use_last_session_id(self):
        connection = Connection("localhost", 30015, "Fuu", "Bar")
        connection.session_id = 3

        msg1 = RequestMessage.new(connection)
        assert msg1.session_id == connection.session_id

        connection.session_id = 5
        msg2 = RequestMessage.new(connection)
        assert msg2.session_id == connection.session_id
开发者ID:martin-zheng,项目名称:PyHDB,代码行数:12,代码来源:test_message.py

示例2: test_pack

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def test_pack():
        connection = Connection("localhost", 30015, "Fuu", "Bar")

        msg = RequestMessage.new(connection, [DummySegment(None)])
        payload = msg.pack()
        packed = payload.getvalue()
        assert isinstance(packed, bytes)

        # Session id
        assert packed[0:8] == b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"

        # Packet count
        assert packed[8:12] == b"\x00\x00\x00\x00"

        # var part length
        assert packed[12:16] == b"\x0A\x00\x00\x00"

        # var part size
        assert packed[16:20] == b"\xE0\xFF\x01\x00"

        # no of segments
        assert packed[20:22] == b"\x01\x00"

        # reserved
        assert packed[22:32] == b"\x00" * 10

        # payload
        assert packed[32:42] == b"\x00" * 10
开发者ID:dpdornseifer,项目名称:PyHDB,代码行数:30,代码来源:test_message.py

示例3: _execute_direct

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def _execute_direct(self, operation):
        """Execute statements which are not going through 'prepare_statement' (aka 'direct execution').
        Either their have no parameters, or Python's string expansion has been applied to the SQL statement.
        :param operation:
        """
        request = RequestMessage.new(
            self.connection,
            RequestSegment(
                message_types.EXECUTEDIRECT,
                Command(operation)
            )
        )
        reply = self.connection.send_request(request)

        parts = reply.segments[0].parts
        function_code = reply.segments[0].function_code
        if function_code == function_codes.SELECT:
            self._handle_select(parts)
        elif function_code in function_codes.DML:
            self._handle_upsert(parts)
        elif function_code == function_codes.DDL:
            # No additional handling is required
            pass
        elif function_code in (function_codes.DBPROCEDURECALL, function_codes.DBPROCEDURECALLWITHRESULT):
            self._handle_dbproc_call(parts, None)
        else:
            raise InterfaceError("Invalid or unsupported function code received: %d" % function_code)
开发者ID:euekim,项目名称:PyHDB,代码行数:29,代码来源:cursor.py

示例4: prepare

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def prepare(self, statement):
        """Prepare SQL statement in HANA and cache it
        :param statement; a valid SQL statement
        :returns: statement_id (of prepared and cached statement)
        """
        self._check_closed()
        self._column_types = None
        statement_id = params_metadata = result_metadata_part = None

        request = RequestMessage.new(
            self.connection,
            RequestSegment(
                message_types.PREPARE,
                Command(statement)
            )
        )
        response = self.connection.send_request(request)

        for part in response.segments[0].parts:
            if part.kind == part_kinds.STATEMENTID:
                statement_id = part.statement_id
            elif part.kind == part_kinds.PARAMETERMETADATA:
                params_metadata = part.values
            elif part.kind == part_kinds.RESULTSETMETADATA:
                result_metadata_part = part

        # Check that both variables have been set in previous loop, we need them:
        assert statement_id is not None
        assert params_metadata is not None
        # cache statement:
        self._prepared_statements[statement_id] = PreparedStatement(self.connection, statement_id,
                                                                    params_metadata, result_metadata_part)
        return statement_id
开发者ID:euekim,项目名称:PyHDB,代码行数:35,代码来源:cursor.py

示例5: connect

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def connect(self):
        with self._socket_lock:
            if self._socket is not None:
                # Socket already established
                return

            self._open_socket_and_init_protocoll()

            # Perform the authenication handshake and get the part
            # with the agreed authentication data
            agreed_auth_part = self._auth_manager.perform_handshake()

            request = RequestMessage.new(
                self,
                RequestSegment(
                    message_types.CONNECT,
                    (
                        agreed_auth_part,
                        ClientId(
                            "pyhdb-%[email protected]%s" % (os.getpid(), socket.getfqdn())
                        ),
                        ConnectOptions(DEFAULT_CONNECTION_OPTIONS)
                    )
                )
            )
            self.send_request(request)
开发者ID:patani1,项目名称:PyHDB,代码行数:28,代码来源:connection.py

示例6: fetchmany

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def fetchmany(self, size=None):
        """Fetch many rows from select result set.
        :param size: Number of rows to return.
        :returns: list of row records (tuples)
        """
        self._check_closed()
        if not self._executed:
            raise ProgrammingError("Require execute() first")
        if size is None:
            size = self.arraysize

        result = []
        cnt = 0
        while cnt != size:
            try:
                result.append(next(self._buffer))
                cnt += 1
            except StopIteration:
                break

        if cnt == size or self._received_last_resultset_part:
            # No rows are missing or there are no additional rows
            return result

        request = RequestMessage.new(
            self.connection,
            RequestSegment(message_types.FETCHNEXT, (ResultSetId(self._resultset_id), FetchSize(size - cnt))),
        )
        response = self.connection.send_request(request)

        resultset_part = response.segments[0].parts[1]
        if resultset_part.attribute & 1:
            self._received_last_resultset_part = True
        result.extend(resultset_part.unpack_rows(self._column_types, self.connection))
        return result
开发者ID:martin-zheng,项目名称:PyHDB,代码行数:37,代码来源:cursor.py

示例7: fetchmany

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def fetchmany(self, size=None):
        self._check_closed()
        if not self._executed:
            raise ProgrammingError("Require execute() first")
        if size is None:
            size = self.arraysize

        _result = []
        _missing = size

        while bool(self._buffer) and _missing > 0:
            _result.append(self._buffer.popleft())
            _missing -= 1

        if _missing == 0 or self._received_last_resultset_part:
            # No rows are missing or there are no additional rows
            return _result

        request = RequestMessage.new(
            self.connection,
            RequestSegment(
                message_types.FETCHNEXT,
                (ResultSetId(self._resultset_id), FetchSize(_missing))
            )
        )
        response = self.connection.send_request(request)

        if response.segments[0].parts[1].attribute & 1:
            self._received_last_resultset_part = True

        resultset_part = response.segments[0].parts[1]
        for row in self._unpack_rows(resultset_part.payload, resultset_part.rows):
            _result.append(row)
        return _result
开发者ID:dpdornseifer,项目名称:PyHDB,代码行数:36,代码来源:cursor.py

示例8: test_request_message_init_with_multiple_segments_as_tuple

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def test_request_message_init_with_multiple_segments_as_tuple():
        connection = Connection("localhost", 30015, "Fuu", "Bar")

        request_seg_1 = RequestSegment(0)
        request_seg_2 = RequestSegment(1)
        msg = RequestMessage.new(connection, (request_seg_1, request_seg_2))
        assert msg.segments == (request_seg_1, request_seg_2)
开发者ID:dpdornseifer,项目名称:PyHDB,代码行数:9,代码来源:test_message.py

示例9: execute_prepared

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def execute_prepared(self, prepared_statement, multi_row_parameters):
        """
        :param prepared_statement: A PreparedStatement instance
        :param multi_row_parameters: A list/tuple containing list/tuples of parameters (for multiple rows)
        """
        self._check_closed()

        # Convert parameters into a generator producing lists with parameters as named tuples (incl. some meta data):
        parameters = prepared_statement.prepare_parameters(multi_row_parameters)

        while parameters:
            request = RequestMessage.new(
                self.connection,
                RequestSegment(
                    message_types.EXECUTE,
                    (StatementId(prepared_statement.statement_id),
                     Parameters(parameters))
                )
            )
            reply = self.connection.send_request(request)

            parts = reply.segments[0].parts
            function_code = reply.segments[0].function_code
            if function_code == function_codes.SELECT:
                self._handle_select(parts, prepared_statement.result_metadata_part)
            elif function_code in function_codes.DML:
                self._handle_upsert(parts, request.segments[0].parts[1].unwritten_lobs)
            elif function_code == function_codes.DDL:
                # No additional handling is required
                pass
            elif function_code in (function_codes.DBPROCEDURECALL, function_codes.DBPROCEDURECALLWITHRESULT):
                self._handle_dbproc_call(parts, prepared_statement._params_metadata) # resultset metadata set in prepare
            else:
                raise InterfaceError("Invalid or unsupported function code received: %d" % function_code)
开发者ID:euekim,项目名称:PyHDB,代码行数:36,代码来源:cursor.py

示例10: rollback

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def rollback(self):
        self._check_closed()

        request = RequestMessage.new(
            self,
            RequestSegment(message_types.ROLLBACK)
        )
        self.send_request(request)
开发者ID:patani1,项目名称:PyHDB,代码行数:10,代码来源:connection.py

示例11: test_invalid_request

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
def test_invalid_request(connection):
    request = RequestMessage.new(
        connection,
        RequestSegment(2)
    )

    with pytest.raises(DatabaseError):
        connection.send_request(request)
开发者ID:Parnswir,项目名称:PyHDB,代码行数:10,代码来源:test_error.py

示例12: test_payload_pack

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def test_payload_pack(self, autocommit):
        connection = Connection("localhost", 30015, "Fuu", "Bar", autocommit=autocommit)

        msg = RequestMessage.new(connection, [DummySegment(None)])
        payload = BytesIO()
        msg.build_payload(payload)

        assert payload.getvalue() == b"\x00" * 10
开发者ID:dpdornseifer,项目名称:PyHDB,代码行数:10,代码来源:test_message.py

示例13: commit

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def commit(self):
        self._check_closed()

        request = RequestMessage.new(
            self,
            RequestSegment(message_types.COMMIT)
        )
        self.send_request(request)
开发者ID:patani1,项目名称:PyHDB,代码行数:10,代码来源:connection.py

示例14: test_request_message_use_last_session_id

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def test_request_message_use_last_session_id():
        connection = Connection("localhost", 30015, "Fuu", "Bar")
        connection.session_id = 1

        msg = RequestMessage.new(connection)
        assert msg.session_id == connection.session_id

        connection.session_id = 5
        assert msg.session_id == connection.session_id
开发者ID:dpdornseifer,项目名称:PyHDB,代码行数:11,代码来源:test_message.py

示例15: test_request_message_keep_packet_count

# 需要导入模块: from pyhdb.protocol.message import RequestMessage [as 别名]
# 或者: from pyhdb.protocol.message.RequestMessage import new [as 别名]
    def test_request_message_keep_packet_count(self, get_next_packet_count):
        connection = Connection("localhost", 30015, "Fuu", "Bar")

        msg = RequestMessage.new(connection)
        assert msg.packet_count == 0

        # Check two time packet count of the message
        # but the get_next_packet_count method of connection
        # should only called once.
        assert msg.packet_count == 0
        get_next_packet_count.assert_called_once_with()
开发者ID:dpdornseifer,项目名称:PyHDB,代码行数:13,代码来源:test_message.py


注:本文中的pyhdb.protocol.message.RequestMessage.new方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。