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


C# SqlString.Trim方法代码示例

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


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

示例1: AddCondition

        public override bool AddCondition(SqlString condition)
        {
            //TODO: this seems hackish
            if (
                afterFrom.ToString().IndexOf(condition.Trim().ToString()) < 0 &&
                afterWhere.ToString().IndexOf(condition.Trim().ToString()) < 0)
            {
                if (!condition.StartsWithCaseInsensitive(" and "))
                {
                    afterWhere.Add(" and ");
                }

                afterWhere.Add(condition);
                return true;
            }

            return false;
        }
开发者ID:zibler,项目名称:zibler,代码行数:18,代码来源:QueryJoinFragment.cs

示例2: AddCondition

 public JoinSequence AddCondition(SqlString condition)
 {
     if (condition.Trim().Length != 0)
     {
         if (!condition.StartsWithCaseInsensitive(" and "))
             conditions.Add(" and ");
         conditions.Add(condition);
     }
     return this;
 }
开发者ID:zibler,项目名称:zibler,代码行数:10,代码来源:JoinSequence.cs

示例3: RemoveSortOrderDirection

		private static SqlString RemoveSortOrderDirection(SqlString sortExpression)
		{
			SqlString trimmedExpression = sortExpression.Trim();
			if (trimmedExpression.EndsWithCaseInsensitive("asc"))
				return trimmedExpression.Substring(0, trimmedExpression.Length - 3).Trim();
			if (trimmedExpression.EndsWithCaseInsensitive("desc"))
				return trimmedExpression.Substring(0, trimmedExpression.Length - 4).Trim();
			return trimmedExpression.Trim();
		}
开发者ID:Tasteful,项目名称:nhibernate-core,代码行数:9,代码来源:MsSql2005DialectQueryPager.cs

示例4: TrimAllParam

		public void TrimAllParam()
		{
			Parameter p1 = Parameter.Placeholder;
			Parameter p2 = Parameter.Placeholder;

			SqlString sql = new SqlString(new object[] { p1, p2 });
			sql = sql.Trim();

			Assert.AreEqual("??", sql.ToString());
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:10,代码来源:SqlStringFixture.cs

示例5: TrimBeginStringEndParam

		public void TrimBeginStringEndParam()
		{
			Parameter p1 = Parameter.Placeholder;

			SqlString sql = new SqlString(new object[] { "   extra space   ", p1 });
			sql = sql.Trim();

			Assert.AreEqual("extra space   ?", sql.ToString());
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:9,代码来源:SqlStringFixture.cs

示例6: TrimBeginParamEndString

		public void TrimBeginParamEndString()
		{
			Parameter p1 = Parameter.Placeholder;

			SqlString sql = new SqlString(new object[] { p1, "   extra space   " });
			sql = sql.Trim();

			Assert.AreEqual("?   extra space", sql.ToString());
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:9,代码来源:SqlStringFixture.cs

示例7: TrimAllString

		public void TrimAllString()
		{
			SqlString sql = new SqlString(new string[] { "   extra space", " in the middle", " at the end     " });
			sql = sql.Trim();

			Assert.AreEqual("extra space in the middle at the end", sql.ToString());
		}
开发者ID:NikGovorov,项目名称:nhibernate-core,代码行数:7,代码来源:SqlStringFixture.cs

示例8: SetOuterJoins

		/// <summary>
		/// Sets the SqlString for the OUTER JOINs.  
		/// </summary>
		/// <remarks>
		/// All of the Sql needs to be included in the SELECT.  No OUTER JOINS will automatically be
		/// added.
		/// </remarks>
		/// <param name="outerJoinsAfterFrom">The outerJoinsAfterFrom to set</param>
		/// <param name="outerJoinsAfterWhere">The outerJoinsAfterWhere to set</param>
		/// <returns>The SqlSelectBuilder</returns>
		public SqlSelectBuilder SetOuterJoins(SqlString outerJoinsAfterFrom, SqlString outerJoinsAfterWhere)
		{
			this.outerJoinsAfterFrom = outerJoinsAfterFrom;

			SqlString tmpOuterJoinsAfterWhere = outerJoinsAfterWhere.Trim();
			if (tmpOuterJoinsAfterWhere.StartsWithCaseInsensitive("and"))
			{
				tmpOuterJoinsAfterWhere = tmpOuterJoinsAfterWhere.Substring(4);
			}

			this.outerJoinsAfterWhere = tmpOuterJoinsAfterWhere;
			return this;
		}
开发者ID:pallmall,项目名称:WCell,代码行数:23,代码来源:SqlSelectBuilder.cs

示例9: GetLimitString

		public override SqlString GetLimitString(SqlString sql, SqlString offset, SqlString limit)
		{
			sql = sql.Trim();
			bool isForUpdate = false;
			if (sql.EndsWithCaseInsensitive(" for update"))
			{
				sql = sql.Substring(0, sql.Length - 11);
				isForUpdate = true;
			}

			string selectColumns = ExtractColumnOrAliasNames(sql);

			var pagingSelect = new SqlStringBuilder(sql.Parts.Count + 10);
			if (offset != null)
			{
				pagingSelect.Add("select " + selectColumns + " from ( select row_.*, rownum rownum_ from ( ");
			}
			else
			{
				pagingSelect.Add("select " + selectColumns + " from ( ");
			}
			pagingSelect.Add(sql);
			if (offset != null && limit != null)
			{
				pagingSelect.Add(" ) row_ where rownum <=").Add(limit).Add(") where rownum_ >").Add(offset);
			}
			else if (limit != null)
			{
				pagingSelect.Add(" ) where rownum <=").Add(limit);
			}
			else
			{
				// offset is specified, but limit is not.
				pagingSelect.Add(" ) row_ ) where rownum_ >").Add(offset);
			}

			if (isForUpdate)
			{
				pagingSelect.Add(" for update");
			}

			return pagingSelect.ToSqlString();
		}
开发者ID:ntuveri,项目名称:nhibernate-core,代码行数:43,代码来源:Oracle8iDialect.cs

示例10: PrepareQueryCommand

		/// <summary>
		/// Obtain an <c>IDbCommand</c> with all parameters pre-bound. Bind positional parameters,
		/// named parameters, and limit parameters.
		/// </summary>
		/// <remarks>
		/// Creates an IDbCommand object and populates it with the values necessary to execute it against the 
		/// database to Load an Entity.
		/// </remarks>
		/// <param name="sqlString">The SqlString to convert into a prepared IDbCommand.</param>
		/// <param name="parameters">The <see cref="QueryParameters"/> to use for the IDbCommand.</param>
		/// <param name="scroll">TODO: find out where this is used...</param>
		/// <param name="session">The SessionImpl this Command is being prepared in.</param>
		/// <returns>An IDbCommand that is ready to be executed.</returns>
		protected virtual IDbCommand PrepareQueryCommand(
			SqlString sqlString,
			QueryParameters parameters,
			bool scroll,
			ISessionImplementor session )
		{
			Dialect.Dialect dialect = session.Factory.Dialect;

			RowSelection selection = parameters.RowSelection;
			bool useLimit = UseLimit( selection, dialect );
			bool hasFirstRow = GetFirstRow( selection ) > 0;
			bool useOffset = hasFirstRow && useLimit && dialect.SupportsLimitOffset;
			//TODO: In .Net all resultsets are scrollable (we receive an IDataReader), so this is not needed
			bool scrollable = session.Factory.IsScrollableResultSetsEnabled &&
				( scroll || ( hasFirstRow && !useOffset ) );

			if( useLimit )
			{
				sqlString = dialect.GetLimitString( sqlString.Trim(),
				                                    useOffset ? GetFirstRow( selection ) : 0,
				                                    GetMaxOrLimit( dialect, selection ) );
			}

			IDbCommand command = session.Batcher.PrepareQueryCommand( sqlString, scrollable );

			try
			{
				// Added in NH - not in H2.1
				if( selection != null && selection.Timeout != RowSelection.NoValue )
				{
					command.CommandTimeout = selection.Timeout;
				}

				int colIndex = 0;

				if( useLimit && dialect.BindLimitParametersFirst )
				{
					colIndex += BindLimitParameters( command, colIndex, selection, session );
				}

				colIndex += BindPositionalParameters( command, parameters, colIndex, session );
				colIndex += BindNamedParameters( command, parameters.NamedParameters, colIndex, session );

				if( useLimit && !dialect.BindLimitParametersFirst )
				{
					colIndex += BindLimitParameters( command, colIndex, selection, session );
				}

				if( !useLimit )
				{
					SetMaxRows( command, selection );
				}
				if( selection != null )
				{
					if( selection.Timeout != RowSelection.NoValue )
					{
						command.CommandTimeout = selection.Timeout;
					}
					// H2.1 handles FetchSize here - not ported
				}

			}
			catch( HibernateException )
			{
				session.Batcher.CloseQueryCommand( command, null );
				throw;
			}
			catch( Exception sqle )
			{
				ADOExceptionReporter.LogExceptions( sqle );
				session.Batcher.CloseQueryCommand( command, null );
				throw;
			}

			return command;
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:89,代码来源:Loader.cs

示例11: GetLimitString

		public override SqlString GetLimitString(SqlString sql, int offset, int limit, int? offsetParameterIndex, int? limitParameterIndex)
		{
			sql = sql.Trim();
			bool hasOffset = offset > 0;
			bool isForUpdate = false;
			if (sql.EndsWithCaseInsensitive(" for update"))
			{
				sql = sql.Substring(0, sql.Length - 11);
				isForUpdate = true;
			}

			var pagingSelect = new SqlStringBuilder(sql.Parts.Count + 10);
			if (hasOffset)
			{
				pagingSelect.Add("select * from ( select row_.*, rownum rownum_ from ( ");
			}
			else
			{
				pagingSelect.Add("select * from ( ");
			}
			pagingSelect.Add(sql);
			if (hasOffset)
			{
				pagingSelect.Add(" ) row_ where rownum <=").AddParameter(limitParameterIndex.Value).Add(") where rownum_ >").AddParameter(offsetParameterIndex.Value);
			}
			else
			{
				pagingSelect.Add(" ) where rownum <=").AddParameter(limitParameterIndex.Value);
			}

			if (isForUpdate)
			{
				pagingSelect.Add(" for update");
			}

			return pagingSelect.ToSqlString();
		}
开发者ID:renefc3,项目名称:nhibernate,代码行数:37,代码来源:Oracle8iDialect.cs

示例12: TrimAllParam

		public void TrimAllParam() 
		{
			Parameter p1 = new Parameter( "p1" );
			Parameter p2 = new Parameter( "p2" );
			
			SqlString sql = new SqlString( new object[] { p1, p2 } );
			sql = sql.Trim();

			Assert.AreEqual( ":p1:p2", sql.ToString() );
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:10,代码来源:SqlStringFixture.cs

示例13: TrimBeginStringEndParam

		public void TrimBeginStringEndParam() 
		{
			Parameter p1 = new Parameter( "p1" );
			
			SqlString sql = new SqlString( new object[] { "   extra space   ", p1 } );
			sql = sql.Trim();

			Assert.AreEqual( "extra space   :p1", sql.ToString() );
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:9,代码来源:SqlStringFixture.cs

示例14: TrimBeginParamEndString

		public void TrimBeginParamEndString() 
		{
			Parameter p1 = new Parameter( "p1" );
			
			SqlString sql = new SqlString( new object[] {p1, "   extra space   "} );
			sql = sql.Trim();

			Assert.AreEqual( ":p1   extra space", sql.ToString() );
		}
开发者ID:rcarrillopadron,项目名称:nhibernate-1.0.2.0,代码行数:9,代码来源:SqlStringFixture.cs

示例15: AddWhereFragment

		public void AddWhereFragment(
				JoinFragment joinFragment,
				SqlString whereFragment,
				QueryNode query,
				FromElement fromElement,
				HqlSqlWalker hqlSqlWalker)
		{
			if (whereFragment == null)
			{
				return;
			}

			if (!fromElement.UseWhereFragment && !joinFragment.HasThetaJoins)
			{
				return;
			}

			whereFragment = whereFragment.Trim();
			if (StringHelper.IsEmpty(whereFragment.ToString()))
			{
				return;
			}

			// Forcefully remove leading ands from where fragments; the grammar will
			// handle adding them
			if (whereFragment.StartsWithCaseInsensitive("and"))
			{
				whereFragment = whereFragment.Substring(4);
			}

			log.Debug("Using unprocessed WHERE-fragment [" + whereFragment +"]");

			SqlFragment fragment = (SqlFragment) Create(HqlSqlWalker.SQL_TOKEN, whereFragment.ToString());

			fragment.SetJoinFragment(joinFragment);
			fragment.FromElement = fromElement;

			if (fromElement.IndexCollectionSelectorParamSpec != null)
			{
				fragment.AddEmbeddedParameter(fromElement.IndexCollectionSelectorParamSpec);
				fromElement.IndexCollectionSelectorParamSpec = null;
			}

			if (hqlSqlWalker.IsFilter())
			{
				//if (whereFragment.IndexOfCaseInsensitive("?") >= 0)
                if (whereFragment.ToString().IndexOf("?") >= 0)
                {
					IType collectionFilterKeyType = hqlSqlWalker.SessionFactoryHelper
							.RequireQueryableCollection(hqlSqlWalker.CollectionFilterRole)
							.KeyType;
					CollectionFilterKeyParameterSpecification paramSpec = new CollectionFilterKeyParameterSpecification(
							hqlSqlWalker.CollectionFilterRole,
							collectionFilterKeyType,
							0
					);
					fragment.AddEmbeddedParameter(paramSpec);
				}
			}

			JoinProcessor.ProcessDynamicFilterParameters(
					whereFragment,
					fragment,
					hqlSqlWalker
			);

			log.Debug("Using processed WHERE-fragment [" + fragment.Text + "]");

			// Filter conditions need to be inserted before the HQL where condition and the
			// theta join node.  This is because org.hibernate.loader.Loader binds the filter parameters first,
			// then it binds all the HQL query parameters, see org.hibernate.loader.Loader.processFilterParameters().
			if (fragment.FromElement.IsFilter || fragment.HasFilterCondition)
			{
				if (_filters == null)
				{
					// Find or create the WHERE clause
					IASTNode where = (IASTNode) query.WhereClause;
					// Create a new FILTERS node as a parent of all filters
					_filters = Create(HqlSqlWalker.FILTERS, "{filter conditions}");
					// Put the FILTERS node before the HQL condition and theta joins
					where.InsertChild(0, _filters);
				}

				// add the current fragment to the FILTERS node
				_filters.AddChild(fragment);
			}
			else
			{
				if (_thetaJoins == null)
				{
					// Find or create the WHERE clause
					IASTNode where = (IASTNode) query.WhereClause;

					// Create a new THETA_JOINS node as a parent of all filters
					_thetaJoins = Create(HqlSqlWalker.THETA_JOINS, "{theta joins}");

					// Put the THETA_JOINS node before the HQL condition, after the filters.
					if (_filters == null)
					{
						where.InsertChild(0, _thetaJoins);
//.........这里部分代码省略.........
开发者ID:jlevitt,项目名称:nhibernate-core,代码行数:101,代码来源:SyntheticAndFactory.cs


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