当前位置: 首页>>代码示例>>C#>>正文


C# SqlStringBuilder.Insert方法代码示例

本文整理汇总了C#中NHibernate.SqlCommand.SqlStringBuilder.Insert方法的典型用法代码示例。如果您正苦于以下问题:C# SqlStringBuilder.Insert方法的具体用法?C# SqlStringBuilder.Insert怎么用?C# SqlStringBuilder.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NHibernate.SqlCommand.SqlStringBuilder的用法示例。


在下文中一共展示了SqlStringBuilder.Insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToSqlString

		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary<string, IFilter> enabledFilters)
		{
			//TODO: add default capacity
			SqlStringBuilder sqlBuilder = new SqlStringBuilder();

			SqlString[] columnNames =
				CriterionUtil.GetColumnNames(_propertyName, _projection, criteriaQuery, criteria, enabledFilters);

			bool opNeeded = false;

			for (int i = 0; i < columnNames.Length; i++)
			{
				if (opNeeded)
				{
					sqlBuilder.Add(" or ");
				}
				opNeeded = true;

				sqlBuilder.Add(columnNames[i])
					.Add(" is not null");
			}

			if (columnNames.Length > 1)
			{
				sqlBuilder.Insert(0, "(");
				sqlBuilder.Add(")");
			}

			return sqlBuilder.ToSqlString();
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:30,代码来源:NotNullExpression.cs

示例2: ToSqlString

		/// <summary>
		/// 
		/// </summary>
		/// <param name="factory"></param>
		/// <param name="persistentClass"></param>
		/// <param name="alias"></param>
		/// <returns></returns>
		public override SqlString ToSqlString( ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses )
		{
			//TODO: add default capacity
			SqlStringBuilder sqlBuilder = new SqlStringBuilder();

			string[ ] columnNames = AbstractCriterion.GetColumns( factory, persistentClass, _propertyName, alias, aliasClasses );

			for( int i = 0; i < columnNames.Length; i++ )
			{
				if( i > 0 )
				{
					sqlBuilder.Add( " and " );
				}

				sqlBuilder.Add( columnNames[ i ] )
					.Add( " is null" );
			}

			if( columnNames.Length > 1 )
			{
				sqlBuilder.Insert( 0, "(" );
				sqlBuilder.Add( ")" );
			}

			return sqlBuilder.ToSqlString();
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:33,代码来源:NullExpression.cs

示例3: ToSqlString

		public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary enabledFilters)
		{
			//TODO: add default capacity
			SqlStringBuilder sqlBuilder = new SqlStringBuilder();

			string[] columnNames = criteriaQuery.GetColumnsUsingProjection(criteria, _propertyName);

			for (int i = 0; i < columnNames.Length; i++)
			{
				if (i > 0)
				{
					sqlBuilder.Add(" and ");
				}

				sqlBuilder.Add(columnNames[i])
					.Add(" is null");
			}

			if (columnNames.Length > 1)
			{
				sqlBuilder.Insert(0, "(");
				sqlBuilder.Add(")");
			}

			return sqlBuilder.ToSqlString();
		}
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:26,代码来源:NullExpression.cs

示例4: InsertAndAdd

		public void InsertAndAdd()
		{
			SqlStringBuilder builder = new SqlStringBuilder();

			builder.Add("col1, col2 ");
			builder.Insert(0, "select ");
			builder.Add("from table ");

			Assert.AreEqual("select col1, col2 from table ", builder.ToSqlString().ToString());
		}
开发者ID:hoangduc007,项目名称:nhibernate-core,代码行数:10,代码来源:SqlStringBuilderFixture.cs

示例5: RemoveAt

		public void RemoveAt() 
		{
			SqlStringBuilder builder = new SqlStringBuilder();

			builder.Add("   select * ");
			builder.Add("from table");
			Assert.AreEqual( "   select * from table", builder.ToSqlString().ToString() );

			builder.RemoveAt(0);
			Assert.AreEqual( "from table", builder.ToSqlString().ToString(), "Removed the first element in the SqlStringBuilder" );

			builder.Insert(0, "SELECT * ");
			Assert.AreEqual( "SELECT * from table", builder.ToSqlString().ToString() );
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:14,代码来源:SqlStringBuilderFixture.cs

示例6: GetLimitString

		/// <summary>
		/// Add a <c>LIMIT</c> clause to the given SQL <c>SELECT</c>
		/// </summary>
		/// <param name="querySqlString">A Query in the form of a SqlString.</param>
		/// <param name="hasOffset">Offset of the first row is not zero</param>
		/// <returns>A new SqlString that contains the <c>LIMIT</c> clause.</returns>
		public override SqlString GetLimitString( SqlString querySqlString, bool hasOffset )
		{
			/*
			 * "select * from (select row_number() over(orderby_clause) as rownum, "
			 * querySqlString_without select
			 * " ) as tempresult where rownum between ? and ?"
			 */
			SqlStringBuilder pagingBuilder = new SqlStringBuilder();
			bool isInOrderBy = false;
			StringBuilder orderByStringBuilder = new StringBuilder();

			// build a new query and extract the order by part
			foreach( object sqlPart in querySqlString.SqlParts )
			{
				string sqlPartString = sqlPart as string;
				if( sqlPartString != null )
				{
					if( sqlPartString.ToLower( System.Globalization.CultureInfo.InvariantCulture ).TrimStart().StartsWith( "order by" ) )
					{
						isInOrderBy = true;
					}
				}

				if( isInOrderBy && sqlPart is string )
				{
					orderByStringBuilder.Append( ( string ) sqlPart );
				}
				else
				{
					pagingBuilder.AddObject( sqlPart );
				}
			}

			string rownumClause = "rownumber() over(" + orderByStringBuilder.ToString() + ") as rownum, ";
			// Add the rownum clause first, right after the original select
			pagingBuilder.Insert( 1, rownumClause );
			// Add the rest
			pagingBuilder.Insert( 0, "select * from (" );
			pagingBuilder.Add( ") as tempresult " );
			
			// Add the where clause
			pagingBuilder.Add( "where rownum " );

			if( hasOffset )
			{
				pagingBuilder.Add( "between " );
				pagingBuilder.Add( new Parameter( "p1", new Int32SqlType() ) ).Add("+1");
				pagingBuilder.Add( " and " );
				pagingBuilder.Add( new Parameter( "p2", new Int32SqlType() ) );
			}
			else
			{
				pagingBuilder.Add( "<= " );
				pagingBuilder.Add( new Parameter( "p1", new Int32SqlType() ) );
			}

			return pagingBuilder.ToSqlString();
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:64,代码来源:DB2Dialect.cs

示例7: ToFragmentString

		/// <summary></summary>
		public SqlString ToFragmentString()
		{
			SqlStringBuilder buf = new SqlStringBuilder( values.Count * 5 );
			buf.Add( columnName );

			if( values.Count > 1 )
			{
				// is a comma needed before the value that's about to be added - it
				// defaults to false because we don't need a comma right away.
				bool commaNeeded = false;

				// if a "null" is in the list of values then we need to manipulate
				// the SqlString a little bit more at the end.
				bool allowNull = false;

				buf.Add( " in (" );
				for( int i = 0; i < values.Count; i++ )
				{
					if( Null.Equals( values[ i ] ) )
					{
						allowNull = true;
					}
					else if ( NotNull.Equals( values[ i ] ) )
					{
						throw new ArgumentOutOfRangeException( "not null makes no sense for in expression" ) ;
					}
					else
					{
						if( commaNeeded )
						{
							buf.Add( StringHelper.CommaSpace );
						}
						buf.Add( ( string ) values[ i ] );

						// a value has been added into the IN clause so the next
						// one needs a comma before it
						commaNeeded = true;
					}
				}

				buf.Add( StringHelper.ClosedParen );

				// if "null" is in the list of values then add to the beginning of the
				// SqlString "is null or [column] (" + [rest of sqlstring here] + ")"
				if( allowNull )
				{
					buf.Insert( 0, " is null or " )
						.Insert( 0, columnName )
						.Insert( 0, StringHelper.OpenParen )
						.Add( StringHelper.ClosedParen );
				}
			}
			else
			{
				object value = values[ 0 ];
				if( Null.Equals( value ) )
				{
					buf.Add( " is null" );
				}
				else if ( NotNull.Equals( value ) )
				{
					buf.Add( " is not null " );
				}
				else
				{
					buf.Add( "=" + values[ 0 ] );
				}
			}
			return buf.ToSqlString();
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:71,代码来源:InFragment.cs


注:本文中的NHibernate.SqlCommand.SqlStringBuilder.Insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。