本文整理汇总了Python中pyhdb.protocol.message.RequestMessage类的典型用法代码示例。如果您正苦于以下问题:Python RequestMessage类的具体用法?Python RequestMessage怎么用?Python RequestMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestMessage类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_request_message_use_last_session_id
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,代码行数:10,代码来源:test_message.py
示例2: test_pack
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,代码行数:28,代码来源:test_message.py
示例3: _execute_direct
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,代码行数:27,代码来源:cursor.py
示例4: prepare
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,代码行数:33,代码来源:cursor.py
示例5: connect
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,代码行数:26,代码来源:connection.py
示例6: fetchmany
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,代码行数:35,代码来源:cursor.py
示例7: fetchmany
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,代码行数:34,代码来源:cursor.py
示例8: test_request_message_init_with_multiple_segments_as_tuple
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,代码行数:7,代码来源:test_message.py
示例9: execute_prepared
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,代码行数:34,代码来源:cursor.py
示例10: rollback
def rollback(self):
self._check_closed()
request = RequestMessage.new(
self,
RequestSegment(message_types.ROLLBACK)
)
self.send_request(request)
开发者ID:patani1,项目名称:PyHDB,代码行数:8,代码来源:connection.py
示例11: test_invalid_request
def test_invalid_request(connection):
request = RequestMessage.new(
connection,
RequestSegment(2)
)
with pytest.raises(DatabaseError):
connection.send_request(request)
开发者ID:Parnswir,项目名称:PyHDB,代码行数:8,代码来源:test_error.py
示例12: test_payload_pack
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,代码行数:8,代码来源:test_message.py
示例13: commit
def commit(self):
self._check_closed()
request = RequestMessage.new(
self,
RequestSegment(message_types.COMMIT)
)
self.send_request(request)
开发者ID:patani1,项目名称:PyHDB,代码行数:8,代码来源:connection.py
示例14: test_request_message_use_last_session_id
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,代码行数:9,代码来源:test_message.py
示例15: test_request_message_keep_packet_count
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,代码行数:11,代码来源:test_message.py
示例16: _perform_lob_write_requests
def _perform_lob_write_requests(self, unwritten_lobs):
"""After sending incomplete LOB data during an INSERT or UPDATE this method will be called.
It sends missing LOB data possibly in multiple LOBWRITE requests for all LOBs.
:param unwritten_lobs: A deque list of LobBuffer instances containing LOB data.
Those buffers have been assembled in the parts.Parameter.pack_lob_data() method.
"""
while unwritten_lobs:
request = RequestMessage.new(
self.connection, RequestSegment(message_types.WRITELOB, WriteLobRequest(unwritten_lobs))
)
self.connection.send_request(request)
开发者ID:martin-zheng,项目名称:PyHDB,代码行数:11,代码来源:cursor.py
示例17: close
def close(self):
with self._socket_lock:
if self._socket is None:
raise Error("Connection already closed")
try:
request = RequestMessage.new(self, RequestSegment(message_types.DISCONNECT))
reply = self.send_request(request)
if reply.segments[0].function_code != function_codes.DISCONNECT:
raise Error("Connection wasn't closed correctly")
finally:
self._socket.close()
self._socket = None
开发者ID:liuzheng712,项目名称:PyHDB,代码行数:13,代码来源:connection.py
示例18: _make_read_lob_request
def _make_read_lob_request(self, readoffset, readlength):
"""Make low level request to HANA database (READLOBREQUEST).
Compose request message with proper parameters and read lob data from second part object of reply.
"""
self._connection._check_closed()
request = RequestMessage.new(
self._connection,
RequestSegment(
message_types.READLOB, (ReadLobRequest(self._lob_header.locator_id, readoffset, readlength),)
),
)
response = self._connection.send_request(request)
# The segment of the message contains two parts.
# 1) StatementContext -> ignored for now
# 2) ReadLobReply -> contains some header information and actual LOB data
data_part = response.segments[0].parts[1]
# return actual lob container (BytesIO/TextIO):
return data_part.data
开发者ID:liuzheng712,项目名称:PyHDB,代码行数:20,代码来源:lobs.py
示例19: perform_handshake
def perform_handshake(self):
request = RequestMessage.new(
self.connection,
RequestSegment(
message_types.AUTHENTICATE,
Authentication(self.user, {self.method: self.client_key})
)
)
response = self.connection.send_request(request, no_reconnect=True)
auth_part = response.segments[0].parts[0]
if self.method not in auth_part.methods:
raise Exception(
"Only unknown authentication methods available: %s" %
b",".join(auth_part.methods.keys())
)
salt, server_key = Fields.unpack_data(
BytesIO(auth_part.methods[self.method])
)
self.client_proof = self.calculate_client_proof([salt], server_key)
return Authentication(self.user, {'SCRAMSHA256': self.client_proof})
开发者ID:hpi-epic,项目名称:PyHDB,代码行数:23,代码来源:auth.py
示例20: test_request_message_init_with_single_segment
def test_request_message_init_with_single_segment():
connection = Connection("localhost", 30015, "Fuu", "Bar")
request_seg = RequestSegment(0)
msg = RequestMessage.new(connection, request_seg)
assert msg.segments == [request_seg]
开发者ID:dpdornseifer,项目名称:PyHDB,代码行数:6,代码来源:test_message.py
注:本文中的pyhdb.protocol.message.RequestMessage类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论