<commit_before>using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using NHibernate.Dialect;
using NHibernate.SqlTypes;
using NHibernate.Util;

namespace NHibernate.Driver
{
	/// <summary>
	/// A NHibernate Driver for using the Firebird data provider located in
	/// <c>FirebirdSql.Data.FirebirdClient</c> assembly.
	/// </summary>
	public class FirebirdClientDriver : ReflectionBasedDriver
	{
		private const string SELECT_CLAUSE_EXP = "(?<=select|where).*";
		private const string CAST_PARAMS_EXP = @"(?<![=<>]\s?|first\s?|skip\s?|between\s|between\s@\bp\w+\b\sand\s)@\bp\w+\b(?!\s?[=<>])";
		private readonly Regex _statementRegEx = new Regex(SELECT_CLAUSE_EXP, RegexOptions.IgnoreCase);
		private readonly Regex _castCandidateRegEx = new Regex(CAST_PARAMS_EXP, RegexOptions.IgnoreCase);
		private readonly FirebirdDialect _fbDialect = new FirebirdDialect();

		/// <summary>
		/// Initializes a new instance of the <see cref="FirebirdClientDriver"/> class.
		/// </summary>
		/// <exception cref="HibernateException">
		/// Thrown when the <c>FirebirdSql.Data.Firebird</c> assembly can not be loaded.
		/// </exception>
		public FirebirdClientDriver()
			: base(
				"FirebirdSql.Data.FirebirdClient",
				"FirebirdSql.Data.FirebirdClient",
				"FirebirdSql.Data.FirebirdClient.FbConnection",
				"FirebirdSql.Data.FirebirdClient.FbCommand")
		{
		}

		public override bool UseNamedPrefixInSql
		{
			get { return true; }
		}

		public override bool UseNamedPrefixInParameter
		{
			get { return true; }
		}

		public override string NamedPrefix
		{
			get { return "@"; }
		}

		public override void AdjustCommand(IDbCommand command)
		{
			var expWithParams = GetStatementsWithCastCandidates(command.CommandText);
			if (string.IsNullOrWhiteSpace(expWithParams))
				return;

			var candidates = GetCastCandidates(expWithParams);
			var castParams = from IDbDataParameter p in command.Parameters
							 where candidates.Contains(p.ParameterName)
							 select p;
			foreach (IDbDataParameter param in castParams)
			{
				TypeCastParam(param, command);
			}
		}

		private string GetStatementsWithCastCandidates(string commandText)
		{
			var match = _statementRegEx.Match(commandText);
			return match.Value;
		}

		private IEnumerable<string> GetCastCandidates(string statement)
		{
			var matches = _castCandidateRegEx.Matches(statement);
			foreach (Match match in matches)
			{
				yield return match.Value;
			}<commit_msg>change parameter type from currency to decimal<commit_after>using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using NHibernate.Dialect;
using NHibernate.SqlTypes;
using NHibernate.Util;

namespace NHibernate.Driver
{
	/// <summary>
	/// A NHibernate Driver for using the Firebird data provider located in
	/// <c>FirebirdSql.Data.FirebirdClient</c> assembly.
	/// </summary>
	public class FirebirdClientDriver : ReflectionBasedDriver
	{
		private const string SELECT_CLAUSE_EXP = "(?<=select|where).*";
		private const string CAST_PARAMS_EXP = @"(?<![=<>]\s?|first\s?|skip\s?|between\s|between\s@\bp\w+\b\sand\s)@\bp\w+\b(?!\s?[=<>])";
		private readonly Regex _statementRegEx = new Regex(SELECT_CLAUSE_EXP, RegexOptions.IgnoreCase);
		private readonly Regex _castCandidateRegEx = new Regex(CAST_PARAMS_EXP, RegexOptions.IgnoreCase);
		private readonly FirebirdDialect _fbDialect = new FirebirdDialect();

		/// <summary>
		/// Initializes a new instance of the <see cref="FirebirdClientDriver"/> class.
		/// </summary>
		/// <exception cref="HibernateException">
		/// Thrown when the <c>FirebirdSql.Data.Firebird</c> assembly can not be loaded.
		/// </exception>
		public FirebirdClientDriver()
			: base(
				"FirebirdSql.Data.FirebirdClient",
				"FirebirdSql.Data.FirebirdClient",
				"FirebirdSql.Data.FirebirdClient.FbConnection",
				"FirebirdSql.Data.FirebirdClient.FbCommand")
		{
		}

		public override bool UseNamedPrefixInSql
		{
			get { return true; }
		}

		public override bool UseNamedPrefixInParameter
		{
			get { return true; }
		}

		public override string NamedPrefix
		{
			get { return "@"; }
		}

		protected override void InitializeParameter(IDbDataParameter dbParam, string name, SqlType sqlType)
		{
			base.InitializeParameter(dbParam, name, sqlType);

			if (sqlType.DbType == DbType.Currency)
			{
				dbParam.DbType = DbType.Decimal;
				dbParam.Precision = 18;
				dbParam.Scale = 4;
			}
		}

		public override void AdjustCommand(IDbCommand command)
		{
			var expWithParams = GetStatementsWithCastCandidates(command.CommandText);
			if (string.IsNullOrWhiteSpace(expWithParams))
				return;

			var candidates = GetCastCandidates(expWithParams);
			var castParams = from IDbDataParameter p in command.Parameters
							 where candidates.Contains(p.ParameterName)
							 select p;
			foreach (IDbDataParameter param in castParams)
			{
				TypeCastParam(param, command);
			}
		}

		private string GetStatementsWithCastCandidates(string commandText)
		{
			var match = _statementRegEx.Match(commandText);
			return match.Value;
		}

		private IEnumerable<string> GetCastCandidates(string statement)
		{
			var matches = _castCandidateRegEx.Matches(statement);
			foreach (Match match in matches)
			{
				yield return match.Value;
			}
{'fraction_non_alphanumeric': 0.11036036036036036, 'fraction_numerical': 0.0005630630630630631, 'mean_word_length': 4.158760890609874, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, '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': '925156', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1644, 'n_words': 369}