<commit_before>using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;

namespace NHibernate.Driver
{
	public class BasicResultSetsCommand: IResultSetsCommand
	{
		private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(BasicResultSetsCommand));
		private SqlString sqlString = new SqlString();

		public BasicResultSetsCommand(ISessionImplementor session)
		{
			Commands = new List<ISqlCommand>();
			Session = session;
		}

		protected List<ISqlCommand> Commands { get; private set; }

		protected ISessionImplementor Session { get; private set; }

		public virtual void Append(ISqlCommand command)
		{
			Commands.Add(command);
			sqlString = sqlString.Append(command.Query).Append(";").Append(Environment.NewLine);
		}

		public bool HasQueries
		{
			get { return Commands.Count > 0; }
		}

		public virtual SqlString Sql
		{
			get { return sqlString; }
		}

		public virtual IDataReader GetReader(int? commandTimeout)
		{
			var batcher = Session.Batcher;
			SqlType[] sqlTypes = Commands.SelectMany(c => c.ParameterTypes).ToArray();
			var command = batcher.PrepareQueryCommand(CommandType.Text, sqlString, sqlTypes);
			if (commandTimeout.HasValue)
			{
				command.CommandTimeout = commandTimeout.Value;
			}
			log.Info(command.CommandText);
			BindParameters(command);
			return new BatcherDataReaderWrapper(batcher, command);
		}

		protected virtual void BindParameters(IDbCommand command)
		{
			var wholeQueryParametersList = Sql.GetParameters().ToList();
			var singleQueryParameterOffset = 0;
			foreach (var sqlLoaderCommand in Commands)
			{
				sqlLoaderCommand.Bind(command, wholeQueryParametersList, singleQueryParameterOffset, Session);
				singleQueryParameterOffset += sqlLoaderCommand.ParameterTypes.Length;
			}
		}
	}

	/// <summary>
	/// Datareader wrapper with the same life cycle of its command (through the batcher)
	/// </summary>
	public class BatcherDataReaderWrapper: IDataReader
	{
		private readonly IBatcher batcher;
		private readonly IDbCommand command;
		private readonly IDataReader reader;

		public BatcherDataReaderWrapper(IBatcher batcher, IDbCommand command)
		{
			if (batcher == null)
			{
				throw new ArgumentNullException("batcher");
			}
			if (command == null)
			{
				throw new ArgumentNullException("command");<commit_msg>Added influence of parameters names for multi queries<commit_after>using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;

namespace NHibernate.Driver
{
	public class BasicResultSetsCommand: IResultSetsCommand
	{
		private static readonly IInternalLogger log = LoggerProvider.LoggerFor(typeof(BasicResultSetsCommand));
		private SqlString sqlString = new SqlString();

		public BasicResultSetsCommand(ISessionImplementor session)
		{
			Commands = new List<ISqlCommand>();
			Session = session;
		}

		protected List<ISqlCommand> Commands { get; private set; }

		protected ISessionImplementor Session { get; private set; }

		public virtual void Append(ISqlCommand command)
		{
			Commands.Add(command);
			sqlString = sqlString.Append(command.Query).Append(";").Append(Environment.NewLine);
		}

		public bool HasQueries
		{
			get { return Commands.Count > 0; }
		}

		public virtual SqlString Sql
		{
			get { return sqlString; }
		}

		public virtual IDataReader GetReader(int? commandTimeout)
		{
			var batcher = Session.Batcher;
			SqlType[] sqlTypes = Commands.SelectMany(c => c.ParameterTypes).ToArray();
			ForEachSqlCommand((sqlLoaderCommand, offset) => sqlLoaderCommand.ResetParametersIndexesForTheCommand(offset));
			var command = batcher.PrepareQueryCommand(CommandType.Text, sqlString, sqlTypes);
			if (commandTimeout.HasValue)
			{
				command.CommandTimeout = commandTimeout.Value;
			}
			log.Info(command.CommandText);
			BindParameters(command);
			return new BatcherDataReaderWrapper(batcher, command);
		}

		protected virtual void BindParameters(IDbCommand command)
		{
			var wholeQueryParametersList = Sql.GetParameters().ToList();
			ForEachSqlCommand((sqlLoaderCommand, offset) => sqlLoaderCommand.Bind(command, wholeQueryParametersList, offset, Session));
		}

		/// <summary>
		/// Execute the given <paramref name="actionToDo"/> for each command of the resultset.
		/// </summary>
		/// <param name="actionToDo">The action to perform where the first parameter is the <see cref="ISqlCommand"/> and the second parameter is the parameters offset of the <see cref="ISqlCommand"/>.</param>
		protected void ForEachSqlCommand(Action<ISqlCommand, int> actionToDo)
		{
			var singleQueryParameterOffset = 0;
			foreach (var sqlLoaderCommand in Commands)
			{
				actionToDo(sqlLoaderCommand, singleQueryParameterOffset);
				singleQueryParameterOffset += sqlLoaderCommand.ParameterTypes.Length;
			}
		}
	}

	/// <summary>
	/// Datareader wrapper with the same life cycle of its command (through the batcher)
	/// </summary>
	public class BatcherDataReaderWrapper: IDataReader
	{
		private readonly IBatcher batcher;
		private readonly IDbCommand command;
		private readonly IDataReader reader;

		public BatcherDataReaderWrapper(IBatcher batcher, IDbCommand command)
		{
			if (batcher == null)
			{
				throw new ArgumentNullException("batcher");
			}
			if (command == null)
			{
				throw new ArgumentNullException("command");
{'fraction_non_alphanumeric': 0.09265000911909539, 'fraction_numerical': 0.0007295276308590188, 'mean_word_length': 4.671147880041365, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '3863109', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1536, 'n_words': 396}