<commit_before>using System.Collections;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using log4net;
using NHibernate.Driver;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;

namespace NHibernate.JetDriver
{
	/// <summary>
	/// Implementation of IDriver for Jet database engine.
	/// Because of the weird JOIN clause syntax, this class has to translate the queries generated by NHibernate
	/// into the Jet syntax. This cannot be done anywhere else without having to heavily modify the logic of query creation.
	/// The translations of queries are cached.
	/// </summary>
	/// <remarks>
	/// <para>
	/// Author: <a href="mailto:<EMAIL>"><NAME></a>
	/// </para>
	/// </remarks>
	public class JetDriver : OleDbDriver
	{
		private static ILog logger = LogManager.GetLogger(typeof(JetDriver));

		private IDictionary _queryCache = new Hashtable();

		public override IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
		{
			SqlString final;
			if (IsSelectStatement(sqlString))
			{
				final = FinalizeJoins(sqlString);
			}
			//else if(IsCreateOrAlterStatement(sqlString)) final = FinalizeDDL(sqlString);
			else
			{
				final = sqlString;
			}

			return base.GenerateCommand(type, final, parameterTypes);
		}

		/// <summary></summary>
		public override IDbConnection CreateConnection()
		{
			return new JetDbConnection();
		}

		/// <summary>
		/// We have to have a special db command type to support conversion of data types, because Access is weird.
		/// </summary>
		public override IDbCommand CreateCommand()
		{
			return new JetDbCommand();
		}

		/// <summary>
		/// MS Access expects @paramName
		/// </summary>
		public override bool UseNamedPrefixInParameter
		{
			get { return true; }
		}

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

		#region Query transformations

		/// <summary>
		///Jet engine has the following from clause syntax:
		///<code>
		///		tableexpression[, tableexpression]*
		///</code>
		///where tableexpression is:
		///<code>
		///		tablename [(INNER |LEFT | RIGHT) JOIN [(] tableexpression [)] ON ...]
		///</code>
		///where the parenthesises are necessary if the "inner" tableexpression is not just a single tablename.
		///Additionally INNER JOIN cannot be nested in LEFT | RIGHT JOIN.
		///To translate the simple non-parenthesized joins to the jet syntax, the following transformation must be done:
		///<code>
		///		A join B on ... join C on ... join D on ..., E join F on ... join G on ..., H join I on ..., J
		///has to be translated as:
		///		(select * from ((A join B on ...) join C on ...) join D on ...) as crazyAlias1, (select * from (E join F on ...) join G on ...) as crazyAlias2, (select * from H join I on ...) as crazyAlias3, J
		///</code>
		/// </summary>
		/// <param name="sqlString">the sqlstring to transform</param>
		/// <returns>sqlstring with parenthesized joins.</returns>
		private SqlString FinalizeJoins(SqlString sqlString)
		{
			if (_queryCache.Contains(sqlString))
			{
				return (SqlString) _queryCache[sqlString];
			}

			SqlStringBuilder beginning = new SqlStringBuilder(sqlString.Count);
			SqlStringBuilder end = new SqlStringBuilder(sqlString.Count);

			int beginOfFrom = sqlString.IndexOfCaseInsensitive("from");
			int endOfFrom = sqlString.IndexOfCaseInsensitive("where");

			if (beginOfFrom < 0)
			{<commit_msg>Minor<commit_after>using System.Collections;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using log4net;
using NHibernate.Driver;
using NHibernate.SqlCommand;
using NHibernate.SqlTypes;

namespace NHibernate.JetDriver
{
	/// <summary>
	/// Implementation of IDriver for Jet database engine.
	/// Because of the weird JOIN clause syntax, this class has to translate the queries generated by NHibernate
	/// into the Jet syntax. This cannot be done anywhere else without having to heavily modify the logic of query creation.
	/// The translations of queries are cached.
	/// </summary>
	/// <remarks>
	/// <para>
	/// Author: <a href="mailto:<EMAIL>"><NAME></a>
	/// </para>
	/// </remarks>
	public class JetDriver : OleDbDriver
	{
		private static ILog logger = LogManager.GetLogger(typeof(JetDriver));

		private IDictionary _queryCache = new Hashtable();

		public override IDbCommand GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
		{
			SqlString final;
			if (IsSelectStatement(sqlString))
			{
				final = FinalizeJoins(sqlString);
			}
			//else if(IsCreateOrAlterStatement(sqlString)) final = FinalizeDDL(sqlString);
			else
			{
				final = sqlString;
			}

			return base.GenerateCommand(type, final, parameterTypes);
		}

		/// <summary></summary>
		public override IDbConnection CreateConnection()
		{
			return new JetDbConnection();
		}

		/// <summary>
		/// We have to have a special db command type to support conversion of data types, because Access is weird.
		/// </summary>
		public override IDbCommand CreateCommand()
		{
			return new JetDbCommand();
		}

		/// <summary>
		/// MS Access expects @paramName
		/// </summary>
		public override bool UseNamedPrefixInParameter
		{
			get { return true; }
		}

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

		#region Query transformations

		/// <summary>
		///Jet engine has the following from clause syntax:
		///<code>
		///		tableexpression[, tableexpression]*
		///</code>
		///where tableexpression is:
		///<code>
		///		tablename [(INNER |LEFT | RIGHT) JOIN [(] tableexpression [)] ON ...]
		///</code>
		///where the parenthesises are necessary if the "inner" tableexpression is not just a single tablename.
		///Additionally INNER JOIN cannot be nested in LEFT | RIGHT JOIN.
		///To translate the simple non-parenthesized joins to the jet syntax, the following transformation must be done:
		///<code>
		///		A join B on ... join C on ... join D on ..., E join F on ... join G on ..., H join I on ..., J
		///has to be translated as:
		///		(select * from ((A join B on ...) join C on ...) join D on ...) as crazyAlias1, (select * from (E join F on ...) join G on ...) as crazyAlias2, (select * from H join I on ...) as crazyAlias3, J
		///</code>
		/// </summary>
		/// <param name="sqlString">the sqlstring to transform</param>
		/// <returns>sqlstring with parenthesized joins.</returns>
		private SqlString FinalizeJoins(SqlString sqlString)
		{
			if (_queryCache.Contains(sqlString))
			{
				return (SqlString) _queryCache[sqlString];
			}

			int beginOfFrom = sqlString.IndexOfCaseInsensitive("from");
			int endOfFrom = sqlString.IndexOfCaseInsensitive("where");

			if (beginOfFrom < 0)
			{
{'fraction_non_alphanumeric': 0.12756400658781256, 'fraction_numerical': 0.0014972301242701003, 'mean_word_length': 3.1387856257744735, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4807734', 'n_tokens_mistral': 2223, 'n_tokens_neox': 1925, 'n_words': 676}