<commit_before>using System;
using System.Collections;
using System.Data;
using System.Text;

using log4net;

using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;
using NHibernate.Type;
using NHibernate.Util;
using NHibernate.Dialect.Function;

using Environment = NHibernate.Cfg.Environment;

namespace NHibernate.Dialect
{
	/// <summary>
	/// Represents a dialect of SQL implemented by a particular RDBMS. Sublcasses
	/// implement NHibernate compatibility with different systems.
	/// </summary>
	/// <remarks>
	/// Subclasses should provide a public default constructor that <c>Register()</c>
	/// a set of type mappings and default Hibernate properties.
	/// </remarks>
	public abstract class Dialect
	{
		private static readonly ILog log = LogManager.GetLogger( typeof( Dialect ) );

		private TypeNames typeNames = new TypeNames( "$1" );
		private IDictionary properties = new Hashtable();
		private IDictionary sqlFunctions;

		private static readonly IDictionary standardAggregateFunctions = new Hashtable();

		/// <summary></summary>
		protected const string DefaultBatchSize = "15";
		/// <summary></summary>
		protected const string NoBatch = "0";

		/// <summary></summary>
		static Dialect()
		{
			standardAggregateFunctions["count"] = new CountQueryFunctionInfo();
			standardAggregateFunctions["avg"] = new AvgQueryFunctionInfo();
			standardAggregateFunctions["max"] = new StandardSQLFunction("max");
			standardAggregateFunctions["min"] = new StandardSQLFunction("min");
			standardAggregateFunctions["sum"] = new SumQueryFunctionInfo();
		}

		/// <summary>
		/// The base constructor for Dialect.
		/// </summary>
		/// <remarks>
		/// Every subclass should override this and call Register() with every <see cref="DbType"/> except
		/// <see cref="DbType.Object"/>, <see cref="DbType.SByte"/>, <see cref="DbType.UInt16"/>, <see cref="DbType.UInt32"/>, 
		/// <see cref="DbType.UInt64"/>, <see cref="DbType.VarNumeric"/>.
		/// 
		/// <para>
		/// The Default properties for this Dialect should also be set - such as whether or not to use outer-joins
		/// and what the batch size should be.
		/// </para>
		/// </remarks>
		protected Dialect()
		{
			log.Info( "Using dialect: " + this );
			sqlFunctions = new Hashtable( standardAggregateFunctions ) ;
		}


		/// <summary>
		/// Characters used for quoting sql identifiers
		/// </summary>
		public const string PossibleQuoteChars = "`'\"[";
		/// <summary></summary>
		public const string PossibleClosedQuoteChars = "`'\"]";

		/// <summary>
		/// Get the name of the database type associated with the given 
		/// <see cref="SqlTypes.SqlType"/>,
		/// </summary>
		/// <param name="sqlType">The SqlType</param>
		/// <returns>The database type name used by ddl.</returns>
		public virtual string GetTypeName( SqlType sqlType )
		{
			if( sqlType.LengthDefined )
			{
				string resultWithLength = typeNames.Get( sqlType.DbType, sqlType.Length );
				if( resultWithLength != null ) return resultWithLength;
			}

			string result = typeNames.Get( sqlType.DbType );
			if( result == null )
			{
				throw new HibernateException( "No default type mapping for SqlType " + sqlType.ToString() );
			}

			return result;
		}

		/// <summary>
		/// Get the name of the database type associated with the given
		/// <see cref="SqlType"/>.
		/// </summary>
		/// <param name="sqlType">The SqlType </param>
		/// <param name="length">The length of the SqlType</param>
		/// <returns>The database type name used by ddl.</returns>
		public virtual string GetTypeName( SqlType sqlType, int length )
		{
			string result = typeNames.Get( sqlType.DbType, length );
			if( result == null )
			{
				throw new HibernateException( "No type mapping for SqlType " + sqlType.ToString() + " of length " + length );
			}
			return result;
		}

		public virtual string GetCastTypeName( SqlType sqlType )
		{
			return GetTypeName(sqlType);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="name"></param>
		/// <param name="function"></param>
		protected void RegisterFunction( string name, ISQLFunction function )
		{
			sqlFunctions.Add( name, function );<commit_msg>NH-760 fix - allow replacing a registered function using RegisterFunction.<commit_after>using System;
using System.Collections;
using System.Data;
using System.Text;

using log4net;

using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;
using NHibernate.Type;
using NHibernate.Util;
using NHibernate.Dialect.Function;

using Environment = NHibernate.Cfg.Environment;

namespace NHibernate.Dialect
{
	/// <summary>
	/// Represents a dialect of SQL implemented by a particular RDBMS. Sublcasses
	/// implement NHibernate compatibility with different systems.
	/// </summary>
	/// <remarks>
	/// Subclasses should provide a public default constructor that <c>Register()</c>
	/// a set of type mappings and default Hibernate properties.
	/// </remarks>
	public abstract class Dialect
	{
		private static readonly ILog log = LogManager.GetLogger( typeof( Dialect ) );

		private TypeNames typeNames = new TypeNames( "$1" );
		private IDictionary properties = new Hashtable();
		private IDictionary sqlFunctions;

		private static readonly IDictionary standardAggregateFunctions = new Hashtable();

		/// <summary></summary>
		protected const string DefaultBatchSize = "15";
		/// <summary></summary>
		protected const string NoBatch = "0";

		/// <summary></summary>
		static Dialect()
		{
			standardAggregateFunctions["count"] = new CountQueryFunctionInfo();
			standardAggregateFunctions["avg"] = new AvgQueryFunctionInfo();
			standardAggregateFunctions["max"] = new StandardSQLFunction("max");
			standardAggregateFunctions["min"] = new StandardSQLFunction("min");
			standardAggregateFunctions["sum"] = new SumQueryFunctionInfo();
		}

		/// <summary>
		/// The base constructor for Dialect.
		/// </summary>
		/// <remarks>
		/// Every subclass should override this and call Register() with every <see cref="DbType"/> except
		/// <see cref="DbType.Object"/>, <see cref="DbType.SByte"/>, <see cref="DbType.UInt16"/>, <see cref="DbType.UInt32"/>, 
		/// <see cref="DbType.UInt64"/>, <see cref="DbType.VarNumeric"/>.
		/// 
		/// <para>
		/// The Default properties for this Dialect should also be set - such as whether or not to use outer-joins
		/// and what the batch size should be.
		/// </para>
		/// </remarks>
		protected Dialect()
		{
			log.Info( "Using dialect: " + this );
			sqlFunctions = new Hashtable( standardAggregateFunctions ) ;
		}


		/// <summary>
		/// Characters used for quoting sql identifiers
		/// </summary>
		public const string PossibleQuoteChars = "`'\"[";
		/// <summary></summary>
		public const string PossibleClosedQuoteChars = "`'\"]";

		/// <summary>
		/// Get the name of the database type associated with the given 
		/// <see cref="SqlTypes.SqlType"/>,
		/// </summary>
		/// <param name="sqlType">The SqlType</param>
		/// <returns>The database type name used by ddl.</returns>
		public virtual string GetTypeName( SqlType sqlType )
		{
			if( sqlType.LengthDefined )
			{
				string resultWithLength = typeNames.Get( sqlType.DbType, sqlType.Length );
				if( resultWithLength != null ) return resultWithLength;
			}

			string result = typeNames.Get( sqlType.DbType );
			if( result == null )
			{
				throw new HibernateException( "No default type mapping for SqlType " + sqlType.ToString() );
			}

			return result;
		}

		/// <summary>
		/// Get the name of the database type associated with the given
		/// <see cref="SqlType"/>.
		/// </summary>
		/// <param name="sqlType">The SqlType </param>
		/// <param name="length">The length of the SqlType</param>
		/// <returns>The database type name used by ddl.</returns>
		public virtual string GetTypeName( SqlType sqlType, int length )
		{
			string result = typeNames.Get( sqlType.DbType, length );
			if( result == null )
			{
				throw new HibernateException( "No type mapping for SqlType " + sqlType.ToString() + " of length " + length );
			}
			return result;
		}

		public virtual string GetCastTypeName( SqlType sqlType )
		{
			return GetTypeName(sqlType);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="name"></param>
		/// <param name="function"></param>
		protected void RegisterFunction( string name, ISQLFunction function )
		{
			sqlFunctions[name] = function;
{'fraction_non_alphanumeric': 0.13774170446407258, 'fraction_numerical': 0.002984005729291, 'mean_word_length': 3.4450928381962864, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 105, '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': '344411', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2417, 'n_words': 737}