<commit_before>namespace EventStore.SqlStorage.DynamicSql
{
	using System;
	using System.Data;
	using System.Text;

	public class DynamicSqlStatementBuilder : IBuildStatements
	{
		private readonly CommandBuilder builder;
		private readonly IAdaptDynamicSqlDialect dialect;
		private readonly Guid tenantId;

		public DynamicSqlStatementBuilder(CommandBuilder builder, IAdaptDynamicSqlDialect dialect)
			: this(builder, dialect, Guid.Empty)
		{
		}
		public DynamicSqlStatementBuilder(CommandBuilder builder, IAdaptDynamicSqlDialect dialect, Guid tenantId)
		{
			this.builder = builder;
			this.dialect = dialect;
			this.tenantId = tenantId;
		}

		public IAdaptSqlDialect Dialect
		{
			get { return this.dialect; }
		}

		public virtual IDbCommand BuildLoadByIdQuery(Guid id, long maxStartingVersion)
		{
			return this.BuildLoadQuery(this.dialect.GetSelectEventsQuery, id, maxStartingVersion);
		}
		public virtual IDbCommand BuildLoadByCommandIdQuery(Guid commandId)
		{
			return this.BuildLoadQuery(this.dialect.GetSelectEventsForCommandQuery, commandId, 0);
		}
		public virtual IDbCommand BuildLoadStartingAfterQuery(Guid id, long version)
		{
			return this.BuildLoadQuery(this.dialect.GetSelectEventsForVersionQuery, id, version);
		}
		private IDbCommand BuildLoadQuery(string commandText, Guid id, long version)
		{
			var command = this.builder.Build(commandText);
			command.AddParameter(this.IdParam, id.ToNull());
			command.AddParameter(this.CurrentVersionParam, version.ToNull());
			return command;
		}

		public virtual IDbCommand BuildSaveCommand(UncommittedEventStream stream, ISerializeObjects serializer)
		{
			var command = this.builder.Build(this.dialect.GetInsertEventsCommand);
			command.AddParameter(this.IdParam, stream.Id.ToNull());
			command.AddParameter(this.InitialVersionParam, stream.ExpectedVersion);
			command.AddParameter(this.CurrentVersionParam, stream.ExpectedVersion + stream.Events.Count);
			command.AddParameter(this.TypeParam, stream.Type == null ? string.Empty : stream.Type.FullName);
			command.AddParameter(this.CommandIdParam, stream.CommandId.ToNull());
			command.AddParameter(this.CommandPayloadParam, serializer.Serialize(stream.Command));<commit_msg>Fixed: Now adding TenantId parameter to command.<commit_after>namespace EventStore.SqlStorage.DynamicSql
{
	using System;
	using System.Data;
	using System.Text;

	public class DynamicSqlStatementBuilder : IBuildStatements
	{
		private readonly CommandBuilder builder;
		private readonly IAdaptDynamicSqlDialect dialect;
		private readonly Guid tenantId;

		public DynamicSqlStatementBuilder(CommandBuilder builder, IAdaptDynamicSqlDialect dialect)
			: this(builder, dialect, Guid.Empty)
		{
		}
		public DynamicSqlStatementBuilder(CommandBuilder builder, IAdaptDynamicSqlDialect dialect, Guid tenantId)
		{
			this.builder = builder;
			this.dialect = dialect;
			this.tenantId = tenantId;
		}

		public IAdaptSqlDialect Dialect
		{
			get { return this.dialect; }
		}

		public virtual IDbCommand BuildLoadByIdQuery(Guid id, long maxStartingVersion)
		{
			return this.BuildLoadQuery(this.dialect.GetSelectEventsQuery, id, maxStartingVersion);
		}
		public virtual IDbCommand BuildLoadByCommandIdQuery(Guid commandId)
		{
			return this.BuildLoadQuery(this.dialect.GetSelectEventsForCommandQuery, commandId, 0);
		}
		public virtual IDbCommand BuildLoadStartingAfterQuery(Guid id, long version)
		{
			return this.BuildLoadQuery(this.dialect.GetSelectEventsForVersionQuery, id, version);
		}
		private IDbCommand BuildLoadQuery(string commandText, Guid id, long version)
		{
			var command = this.builder.Build(commandText);
			command.AddParameter(this.IdParam, id.ToNull());
			command.AddParameter(this.CurrentVersionParam, version.ToNull());
			return command;
		}

		public virtual IDbCommand BuildSaveCommand(UncommittedEventStream stream, ISerializeObjects serializer)
		{
			var command = this.builder.Build(this.dialect.GetInsertEventsCommand);
			command.AddParameter(this.IdParam, stream.Id.ToNull());
			command.AddParameter(this.TenantIdParam, this.tenantId.ToNull());
			command.AddParameter(this.InitialVersionParam, stream.ExpectedVersion);
			command.AddParameter(this.CurrentVersionParam, stream.ExpectedVersion + stream.Events.Count);
			command.AddParameter(this.TypeParam, stream.Type == null ? string.Empty : stream.Type.FullName);
			command.AddParameter(this.CommandIdParam, stream.CommandId.ToNull());
			command.AddParameter(this.CommandPayloadParam, serializer.Serialize(stream.Command));
{'fraction_non_alphanumeric': 0.08649602824360106, 'fraction_numerical': 0.000441306266548985, 'mean_word_length': 5.7155555555555555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5833223', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1288, 'n_words': 257}