當前位置: 首頁>>代碼示例>>C#>>正文


C# SqlStringBuilder.AddObject方法代碼示例

本文整理匯總了C#中NHibernate.SqlCommand.SqlStringBuilder.AddObject方法的典型用法代碼示例。如果您正苦於以下問題:C# SqlStringBuilder.AddObject方法的具體用法?C# SqlStringBuilder.AddObject怎麽用?C# SqlStringBuilder.AddObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在NHibernate.SqlCommand.SqlStringBuilder的用法示例。


在下文中一共展示了SqlStringBuilder.AddObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Render

        public SqlString Render(IList args, ISessionFactoryImplementor factory)
        {
            if (args.Count < 2)
            {
                throw new QueryException("coalesce() requires at least two arguments");
            }
            
            var sb = new SqlStringBuilder();

            sb.Add("Switch");
            sb.Add("(");
            for (int i = 0; i < args.Count; i++)
            {
                if (i>0)
                {
                    sb.Add(",");  
                }
                var arg = args[i];
                sb.Add("not IsNull(");
                sb.AddObject(arg);
                sb.Add(")");
                sb.Add(",");
                sb.AddObject(arg); 
            }

            sb.Add(",");  
            sb.Add("1=1");
            sb.Add(",");
            sb.AddObject(args[args.Count - 1]);

            sb.Add(")");

            return sb.ToSqlString();
        }
開發者ID:tgmayfield,項目名稱:nhibernate.jetdriver,代碼行數:34,代碼來源:JetCoalesceFunction.cs

示例2: Render

		public SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			//ANSI-SQL92 definition
			//<general set function> ::=
			//<set function type> <leftparen> [ <setquantifier> ] <value expression> <right paren>
			//<set function type> : := AVG | MAX | MIN | SUM | COUNT
			//<setquantifier> ::= DISTINCT | ALL

			if (args.Count < 1 || args.Count > 2)
			{
				throw new QueryException(string.Format("Aggregate {0}(): Not enough parameters (attended from 1 to 2).", name));
			}
			else if ("*".Equals(args[args.Count - 1]) && !acceptAsterisk)
			{
				throw new QueryException(string.Format("Aggregate {0}(): invalid argument '*'.", name));
			}
			SqlStringBuilder cmd = new SqlStringBuilder();
			cmd.Add(name)
				.Add("(");
			if (args.Count > 1)
			{
				object firstArg = args[0];
				if (!StringHelper.EqualsCaseInsensitive("distinct", firstArg.ToString()) &&
				    !StringHelper.EqualsCaseInsensitive("all", firstArg.ToString()))
				{
					throw new QueryException(string.Format("Aggregate {0}(): token unknow {1}.", name, firstArg));
				}
				cmd.AddObject(firstArg).Add(" ");
			}
			cmd.AddObject(args[args.Count - 1])
				.Add(")");
			return cmd.ToSqlString();
		}
開發者ID:ray2006,項目名稱:WCell,代碼行數:33,代碼來源:ClassicAggregateFunction.cs

示例3: Render

		public SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			// TODO: QueryException if args.Count<2 (not present in H3.2) 
			bool threeArgs = args.Count > 2;
			object pattern = args[0];
			object orgString = args[1];
			object start = threeArgs ? args[2] : null;

			SqlStringBuilder buf = new SqlStringBuilder();
			buf.Add("charindex(")
				.AddObject(pattern)
				.Add(", ");
			if (threeArgs)
			{
				buf.Add("right(");
			}
			buf.AddObject(orgString);
			if (threeArgs)
			{
				buf.Add(", char_length(")
					.AddObject(orgString)
					.Add(")-(")
					.AddObject(start)
					.Add("-1))");
			}
			buf.Add(")");
			return buf.ToSqlString();
		}
開發者ID:hazzik,項目名稱:nh-contrib-everything,代碼行數:28,代碼來源:CharIndexFunction.cs

示例4: Render

        public override SqlString Render(IList args, ISessionFactoryImplementor factory)
        {
            bool hasArgs = args.Count > 0;

            SqlStringBuilder buf = new SqlStringBuilder();
            buf.Add(name);
            if (hasArgs)
            {
                buf.Add("(");
                for (int i = 0; i < args.Count; i++)
                {
                    object arg = args[i];
                    if (arg is Parameter || arg is SqlString)
                    {
                        buf.AddObject(arg);
                    }
                    else
                    {
                        buf.Add(arg.ToString());
                    }
                    if (i < (args.Count - 1)) buf.Add(", ");
                }
                buf.Add(")");
            }
            return buf.ToSqlString();
        }
開發者ID:mnjstwins,項目名稱:NHibernate.CacheDb,代碼行數:26,代碼來源:ConditionalParenthesisFunction.cs

示例5: Render

 /// <summary>
 /// Render the function call as SQL.
 /// </summary>
 /// <param name="args">List of arguments</param>
 /// <param name="factory"></param>
 /// <returns>SQL fragment for the function.</returns>
 public override SqlString Render(IList args, ISessionFactoryImplementor factory)
 {
     SqlStringBuilder builder = new SqlStringBuilder();
     builder.AddObject(args[0]);
     builder.Add(".");
     builder.Add(name);
     return builder.ToSqlString();
 }
開發者ID:abrobston,項目名稱:NHibernate.Spatial,代碼行數:14,代碼來源:SpatialPropertyFunction.cs

示例6: Render

 /// <summary>
 /// Render the function call as SQL.
 /// </summary>
 /// <param name="args">List of arguments</param>
 /// <param name="factory"></param>
 /// <returns>SQL fragment for the function.</returns>
 public override SqlString Render(IList args, ISessionFactoryImplementor factory)
 {
     SqlStringBuilder builder = new SqlStringBuilder();
     builder.AddObject(args[0]);
     builder.Add(".");
     builder.Add(name);
     builder.Add("(");
     for (int i = 1; i < args.Count; i++)
     {
         builder.AddObject(args[i]);
         if (i < (args.Count - 1))
         {
             builder.Add(", ");
         }
     }
     builder.Add(")");
     return builder.ToSqlString();
 }
開發者ID:abrobston,項目名稱:NHibernate.Spatial,代碼行數:24,代碼來源:SpatialMethodFunction.cs

示例7: Render

		public SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			SqlStringBuilder buf = new SqlStringBuilder().Add(begin);
			for (int i = 0; i < args.Count; i++)
			{
				buf.AddObject(args[i]);
				if (i < args.Count - 1) buf.Add(sep);
			}
			return buf.Add(end).ToSqlString();
		}
開發者ID:ray2006,項目名稱:WCell,代碼行數:10,代碼來源:VarArgsSQLFunction.cs

示例8: Render

        public SqlString Render(IList args, ISessionFactoryImplementor factory)
        {
            if (args.Count != 2)
            {
                throw new QueryException("NullIf() requires two arguments");
            }

            var sb = new SqlStringBuilder();

            sb.Add("iif");
            sb.Add("(");
            sb.AddObject(args[0]);
            sb.Add("=");
            sb.AddObject(args[1]);
            sb.Add(",");
            sb.Add("NULL");
            sb.Add(",");
            sb.AddObject(args[0]);
            sb.Add(")");


            return sb.ToSqlString();
        }
開發者ID:tgmayfield,項目名稱:nhibernate.jetdriver,代碼行數:23,代碼來源:JetNullIfFunction.cs

示例9: Render

        /// <summary>
        /// 
        /// </summary>
        /// <param name="args"></param>
        /// <param name="factory"></param>
        /// <returns></returns>
        public SqlString Render(IList args, ISessionFactoryImplementor factory)
        {
            SqlStringBuilder buffer = new SqlStringBuilder();
            buffer.Add(this.nameFunction);
            buffer.Add(begin);

            for (int i = 0; i < args.Count; i++)
            {
                buffer.AddObject(args[i]);
                if (i < args.Count - 1)
                    buffer.Add(sep);
            }
            buffer.Add(end);
            return buffer.ToSqlString();
        }
開發者ID:TheHunter,項目名稱:NHibernate.Integration,代碼行數:21,代碼來源:ScalarArgsSqlFunction.cs

示例10: ToSqlStringFragment

		/// <summary></summary>
		public SqlString ToSqlStringFragment()
		{
			SqlStringBuilder buf = new SqlStringBuilder(lhs.Length * 4);
			string prefix = tableAlias + StringHelper.Dot;
			for (int i = 0; i < lhs.Length; i++)
			{
				buf.Add(prefix)
					.Add(lhs[i] + op);

				buf.AddObject(rhs[i]);

				if (i < lhs.Length - 1)
				{
					buf.Add(" and ");
				}
			}
			return buf.ToSqlString();
		}
開發者ID:Novthirteen,項目名稱:sconit_timesseiko,代碼行數:19,代碼來源:ConditionalFragment.cs

示例11: Join

		public static SqlString Join(SqlString separator, IEnumerable objects)
		{
			SqlStringBuilder buf = new SqlStringBuilder();
			bool first = true;

			foreach (object obj in objects)
			{
				if (!first)
				{
					buf.Add(separator);
				}

				first = false;
				buf.AddObject(obj);
			}

			return buf.ToSqlString();
		}
開發者ID:paulbatum,項目名稱:nhibernate,代碼行數:18,代碼來源:StringHelper.cs

示例12: Render

		public SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			// DONE: QueryException if args.Count<2 (not present in H3.2) 
			if (args.Count < 2)
			{
				throw new QueryException("position(): Not enough parameters (attended from 2 to 3).");
			}
			bool threeArgs = args.Count > 2;
			object pattern = args[0];
			object orgString = args[1];
			object start = threeArgs ? args[2] : null;

			SqlStringBuilder buf = new SqlStringBuilder();
			if (threeArgs)
			{
				buf.Add("(");
			}
			buf.Add("position(")
				.AddObject(pattern)
				.Add(" in ");
			if (threeArgs)
			{
				buf.Add("substring(");
			}
			buf.AddObject(orgString);
			if (threeArgs)
			{
				buf.Add(", ")
					.AddObject(start)
					.Add(")");
			}
			buf.Add(")");
			if (threeArgs)
			{
				buf.Add("+")
					.AddObject(start)
					.Add("-1)");
			}
			return buf.ToSqlString();
		}
開發者ID:jlevitt,項目名稱:nhibernate-core,代碼行數:40,代碼來源:PositionSubstringFunction.cs

示例13: Render

		/// <summary>
		/// Applies the template to passed in arguments.
		/// </summary>
		/// <param name="args">args function arguments</param>
		/// <param name="factory">generated SQL function call</param>
		/// <returns></returns>
		public SqlString Render(IList args, ISessionFactoryImplementor factory)
		{
			SqlStringBuilder buf = new SqlStringBuilder();
			foreach (TemplateChunk tc in chunks)
			{
				if (tc.ArgumentIndex != InvalidArgumentIndex)
				{
					int adjustedIndex = tc.ArgumentIndex - 1; // Arg indices are one-based
					object arg = adjustedIndex < args.Count ? args[adjustedIndex] : null;
					// TODO: if (arg == null) QueryException is better ?
					if (arg != null)
					{
						if (arg is Parameter || arg is SqlString)
						{
							buf.AddObject(arg);
						}
						else
						{
							buf.Add(arg.ToString());
						}
					}
				}
				else
				{
					buf.Add(tc.Text);
				}
			}
			return buf.ToSqlString();
		}
開發者ID:hazzik,項目名稱:nh-contrib-everything,代碼行數:35,代碼來源:SQLFunctionTemplate.cs

示例14: Insert

		public SqlString Insert(int index, string text)
		{
			if (index < 0)
			{
				throw new ArgumentException("index should be greater than or equal to 0", "index");
			}

			SqlStringBuilder result = new SqlStringBuilder();

			int offset = 0;
			bool inserted = false;
			foreach (object part in sqlParts)
			{
				if (inserted)
				{
					result.AddObject(part);
					continue;
				}

				int nextOffset = offset + LengthOfPart(part);
				if (nextOffset < index)
				{
					result.AddObject(part);
					offset = nextOffset;
				}
				else if (nextOffset == index)
				{
					result.AddObject(part);
					result.Add(text);
					inserted = true;
				}
				else if (offset == index)
				{
					result.Add(text);
					result.AddObject(part);
					inserted = true;
				}
				else if (index > offset && index < nextOffset)
				{
					string partString = (string) part;
					result.Add(partString.Insert(index - offset, text));
					inserted = true;
				}
				else
				{
					throw new ArgumentException("index too large", "index");
				}
			}

			return result.ToSqlString();
		}
開發者ID:remcoros,項目名稱:nhibernate,代碼行數:51,代碼來源:SqlString.cs

示例15: GetLimitString

        private SqlString GetLimitString(SqlString querySqlString, object offset, object limit)
        {
            SqlStringBuilder pagingBuilder = new SqlStringBuilder();
            pagingBuilder.Add(querySqlString);

            if (limit != null)
            {
                pagingBuilder.Add(" limit ");
                pagingBuilder.AddObject(limit);
            }

            if (offset != null)
            {
                pagingBuilder.Add(" offset ");
                pagingBuilder.AddObject(offset);
            }

            return pagingBuilder.ToSqlString();
        }
開發者ID:pontillo,項目名稱:PowerNap,代碼行數:19,代碼來源:PostgreSQLDialect.cs


注:本文中的NHibernate.SqlCommand.SqlStringBuilder.AddObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。