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 " "5 or higher. Consider setting Cluster.protocol_version to 5." ) 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 5." "".format(flags=flags, pv=protocol_version)) if ProtocolVersion.uses_keyspace_flag(protocol_version): if self.keyspace: write_string(f, self.keyspace)
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 " "5 or higher. Consider setting Cluster.protocol_version to 5.") 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 5." "".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 3.9 @jira_ticket PYTHON-713 @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): self.assertEqual(len(io.write.mock_calls), 3) 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)