def send_body(self, f, protocol_version): write_longstring(f, self.query) flags = 0x00 if self.keyspace is not None: if ProtocolVersion.uses_keyspace_flag(protocol_version): flags |= _PREPARED_WITH_KEYSPACE_FLAG else: raise UnsupportedOperation( "Keyspaces may only be set on queries with protocol version " "DSE_V2 or higher. Consider setting Cluster.protocol_version to ProtocolVersion.DSE_V2." ) if ProtocolVersion.uses_prepare_flags(protocol_version): write_uint(f, flags) else: # checks above should prevent this, but just to be safe... if flags: raise UnsupportedOperation( "Attempted to set flags with value {flags:0=#8x} on" "protocol version {pv}, which doesn't support flags" "in prepared statements." "Consider setting Cluster.protocol_version to ProtocolVersion.DSE_V2." "".format(flags=flags, pv=protocol_version)) if ProtocolVersion.uses_keyspace_flag(protocol_version): if self.keyspace: write_string(f, self.keyspace)
def test_prepare_flag(self): """ Test to check the prepare flag is properly set, This should only happen for V5 at the moment. @since DSE 2.0b3 GRAPH 1.0b1 @jira_ticket PYTHON-694 @expected_result the values are correctly written @test_category connection """ message = PrepareMessage("a") io = Mock() for version in ProtocolVersion.SUPPORTED_VERSIONS: message.send_body(io, version) if ProtocolVersion.uses_prepare_flags(version): # This should pass after PYTHON-696 self.assertEqual(len(io.write.mock_calls), 3) # self.assertEqual(uint32_unpack(io.write.mock_calls[2][1][0]) & _WITH_SERIAL_CONSISTENCY_FLAG, 1) else: self.assertEqual(len(io.write.mock_calls), 2) io.reset_mock()
def send_body(self, f, protocol_version): write_longstring(f, self.query) if ProtocolVersion.uses_prepare_flags(protocol_version): # Write the flags byte; with 0 value for now, but this should change in PYTHON-678 write_uint(f, 0)