⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nvlfunction.cs

📁 NHibernate NET开发者所需的
💻 CS
字号:
using System;
using System.Collections;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.Type;

namespace NHibernate.Dialect.Function
{
	/// <summary>
	/// Emulation of coalesce() on Oracle, using multiple nvl() calls
	/// </summary>
	public class NvlFunction : ISQLFunction
	{
		public NvlFunction()
		{
		}

		#region ISQLFunction Members

		public IType ReturnType(IType columnType, IMapping mapping)
		{
			return columnType;
		}

		public bool HasArguments
		{
			get { return true; }
		}

		public bool HasParenthesesIfNoArguments
		{
			get { return true; }
		}

		public SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			// DONE: QueryException if args.Count==0 (not present in H3.2)
			if (args.Count == 0)
			{
				throw new QueryException("nvl(): Not enough parameters.");
			}
			int lastIndex = args.Count - 1;
			object last = args[lastIndex];
			args.RemoveAt(lastIndex);
			if (lastIndex == 0)
			{
				return new SqlString(last);
			}
			object secondLast = args[lastIndex - 1];
			SqlStringBuilder nvl = new SqlStringBuilder(5)
				.Add("nvl(")
				.AddObject(secondLast)
				.Add(", ")
				.AddObject(last)
				.Add(")");
			args[lastIndex - 1] = nvl.ToSqlString();
			return Render(args, factory);
		}

		#endregion
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -