コード例 #1
0
		/// <returns><see cref="IList" /> of <see cref="IType" /></returns>
		protected SqlType[] GetParameterTypes(QueryParameters parameters, bool addLimit, bool addOffset)
		{
			List<IType> paramTypeList = new List<IType>();
			int span = 0;

			for (int index = 0; index < parameters.PositionalParameterTypes.Length; index++)
			{
				int location = parameters.PositionalParameterLocations[index];
				location = parameters.FindAdjustedParameterLocation(location);
				IType type = parameters.PositionalParameterTypes[index];
				ArrayHelper.SafeSetValue(paramTypeList, location, type);
				span += type.GetColumnSpan(Factory);
			}

			for (int index = 0; index < parameters.FilteredParameterTypes.Count; index++)
			{
				int location = parameters.FilteredParameterLocations[index];
				IType type = parameters.FilteredParameterTypes[index];
				ArrayHelper.SafeSetValue(paramTypeList, location, type);
				span += type.GetColumnSpan(Factory);
			}

			if (parameters.NamedParameters != null && parameters.NamedParameters.Count > 0)
			{
				// convert the named parameters to an array of types
				foreach (KeyValuePair<string, TypedValue> namedParameter in parameters.NamedParameters)
				{
					string name = namedParameter.Key;
					TypedValue typedval = namedParameter.Value;
					int[] locs = GetNamedParameterLocs(name);
					span += typedval.Type.GetColumnSpan(Factory) * locs.Length;

					for (int i = 0; i < locs.Length; i++)
					{
						int location = locs[i];
						location = parameters.FindAdjustedParameterLocation(location);

						// can still clash with positional parameters
						//  could consider throwing an exception to locate problem (NH-1098)
						while ((location < paramTypeList.Count) && (paramTypeList[location] != null))
							location++;

						ArrayHelper.SafeSetValue(paramTypeList, location, typedval.Type);
					}
				}
			}

			if (addLimit && Factory.Dialect.SupportsVariableLimit)
			{
				if (Factory.Dialect.BindLimitParametersFirst)
				{
					paramTypeList.Insert(0, NHibernateUtil.Int32);
					if (addOffset)
					{
						paramTypeList.Insert(0, NHibernateUtil.Int32);
					}
				}
				else
				{
					paramTypeList.Add(NHibernateUtil.Int32);
					if (addOffset)
					{
						paramTypeList.Add(NHibernateUtil.Int32);
					}
				}

				span += addOffset ? 2 : 1;
			}

			return ConvertITypesToSqlTypes(paramTypeList, span);
		}