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


C# SqlGenerator.GetSQL方法代码示例

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


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

示例1: BasicExecutor

		public BasicExecutor(IStatement statement, IQueryable persister)
			: base(statement, log)
		{
			this.persister = persister;
			try
			{
				var gen = new SqlGenerator(Factory, new CommonTreeNodeStream(statement));
				gen.statement();
				sql = gen.GetSQL();
				gen.ParseErrorHandler.ThrowQueryException();
				Parameters = gen.GetCollectedParameters();
			}
			catch (RecognitionException e)
			{
				throw QuerySyntaxException.Convert(e);
			}
		}
开发者ID:juanplopes,项目名称:nhibernate,代码行数:17,代码来源:BasicExecutor.cs

示例2: GenerateIdInsertSelect

		protected SqlString GenerateIdInsertSelect(IQueryable persister, string tableAlias, IASTNode whereClause)
		{
			var select = new SqlSelectBuilder(Factory);
			SelectFragment selectFragment = new SelectFragment(Factory.Dialect)
				.AddColumns(tableAlias, persister.IdentifierColumnNames, persister.IdentifierColumnNames);
			select.SetSelectClause(selectFragment.ToFragmentString().Substring(2));

			string rootTableName = persister.TableName;
			SqlString fromJoinFragment = persister.FromJoinFragment(tableAlias, true, false);
			select.SetFromClause(rootTableName + " " + tableAlias + fromJoinFragment);
			
			var whereJoinFragment = GetWhereJoinFragment(persister, tableAlias);

			SqlString userWhereClause = SqlString.Empty;
			if (whereClause.ChildCount != 0)
			{
				// If a where clause was specified in the update/delete query, use it to limit the
				// returned ids here...
				try
				{
					var nodes = new CommonTreeNodeStream(whereClause);
					var gen = new SqlGenerator(Factory, nodes);
					gen.whereClause();
					userWhereClause = gen.GetSQL().Substring(7);
				}
				catch (RecognitionException e)
				{
					throw new HibernateException("Unable to generate id select for DML operation", e);
				}
				if (whereJoinFragment.Length > 0)
				{
					whereJoinFragment.Append(" and ");
				}
			}

			select.SetWhereClause(whereJoinFragment + userWhereClause);

			var insert = new InsertSelect();
			if (Factory.Settings.IsCommentsEnabled)
			{
				insert.SetComment("insert-select for " + persister.EntityName + " ids");
			}
			insert.SetTableName(persister.TemporaryIdTableName);
			insert.SetSelect(select);
			return insert.ToSqlString();
		}
开发者ID:thilaknathen,项目名称:nhibernate-core,代码行数:46,代码来源:AbstractStatementExecutor.cs

示例3: Resolve

		public override void  Resolve(bool generateJoin, bool implicitJoin, string classAlias, IASTNode parent)
		{
			if (IsResolved) 
			{
				return;
			}

			FromReferenceNode collectionNode = ( FromReferenceNode ) GetChild(0);
			SessionFactoryHelperExtensions sessionFactoryHelper = SessionFactoryHelper;
			collectionNode.ResolveIndex( this );		// Fully resolve the map reference, create implicit joins.

			IType type = collectionNode.DataType;
			if ( !type.IsCollectionType ) 
			{
				throw new SemanticException( "The [] operator cannot be applied to type " + type);
			}

			string collectionRole = ( ( CollectionType ) type ).Role;
			IQueryableCollection queryableCollection = sessionFactoryHelper.RequireQueryableCollection( collectionRole );
			if ( !queryableCollection.HasIndex ) 
			{
				throw new QueryException( "unindexed fromElement before []: " + collectionNode.Path );
			}

			// Generate the inner join -- The elements need to be joined to the collection they are in.
			FromElement fromElement = collectionNode.FromElement;
			String elementTable = fromElement.TableAlias;
			FromClause fromClause = fromElement.FromClause;
			String path = collectionNode.Path;

			FromElement elem = fromClause.FindCollectionJoin( path );
			if ( elem == null ) 
			{
				FromElementFactory factory = new FromElementFactory( fromClause, fromElement, path );
				elem = factory.CreateCollectionElementsJoin( queryableCollection, elementTable );
				if ( Log.IsDebugEnabled )
				{
					Log.Debug( "No FROM element found for the elements of collection join path " + path
							+ ", created " + elem );
				}
			}
			else 
			{
				if ( Log.IsDebugEnabled ) 
				{
					Log.Debug( "FROM element found for collection join path " + path );
				}
			}

			// The 'from element' that represents the elements of the collection.
			FromElement = fromElement;

			// Add the condition to the join sequence that qualifies the indexed element.
			IASTNode selector = GetChild(1);
			if ( selector == null ) 
			{
				throw new QueryException( "No index value!" );
			}

			// Sometimes use the element table alias, sometimes use the... umm... collection table alias (many to many)
			String collectionTableAlias = elementTable;
			if ( elem.CollectionTableAlias != null ) 
			{
				collectionTableAlias = elem.CollectionTableAlias;
			}

			// TODO: get SQL rendering out of here, create an AST for the join expressions.
			// Use the SQL generator grammar to generate the SQL text for the index expression.
			JoinSequence joinSequence = fromElement.JoinSequence;
			string[] indexCols = queryableCollection.IndexColumnNames;
			if ( indexCols.Length != 1 ) 
			{
				throw new QueryException( "composite-index appears in []: " + collectionNode.Path );
			}

			SqlGenerator gen = new SqlGenerator(SessionFactoryHelper.Factory, new CommonTreeNodeStream(selector));

			try 
			{
				gen.simpleExpr(); //TODO: used to be exprNoParens! was this needed?
			}
			catch ( RecognitionException e ) 
			{
				throw new QueryException( e.Message, e );
			}

			string selectorExpression = gen.GetSQL().ToString();

			joinSequence.AddCondition(new SqlString(collectionTableAlias + '.' + indexCols[0] + " = " + selectorExpression ));
			//joinSequence.AddCondition(collectionTableAlias, new string[] { indexCols[0] }, selectorExpression, false);

			IList<IParameterSpecification> paramSpecs = gen.GetCollectedParameters();
			if ( paramSpecs != null ) 
			{
				switch ( paramSpecs.Count ) 
				{
					case 0 :
						// nothing to do
						break;
					case 1 :
//.........这里部分代码省略.........
开发者ID:marchlud,项目名称:nhibernate-core,代码行数:101,代码来源:IndexNode.cs


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