Пример #1
0
		private bool ReplaceAxisCallback(Expression node, object[] noargs) // note: internal longhorn name found on www.winfx247.com
		{
			if( node.NodeType == NodeType.Axis )
			{
				Axis axis = (Axis)node;
				
				// convert the axis into a filter (don't want any axis nodes in final tree)
				Expression filter = new Filter(axis);

				// see if we need to wrap the filter with an exist node
				// note: this is needed when:
				//		1) the source property of the axis is relational
				//		2) the parent of the axis is not already an exists (for future support for the exists keyword)
				//		3) the axis is not in the source of its parent filter
				if( axis.Owner.NodeType != NodeType.Unary || ((Unary)axis.Owner).Operator != UnaryOperator.Exists )
				{
					// get the source property for this axis
					Property property;
					if( axis.Source.NodeType == NodeType.Property )
					{
						property = (Property)axis.Source;
					}
					else if( axis.Source.NodeType == NodeType.Filter || axis.Source.NodeType == NodeType.Axis )
					{
						property = (Property)(axis.Source as Filter).Source;
					}
					else // source not property, filter, or axis
					{
						throw new Exception("Axis source node type of '" + axis.Source.NodeType + "' was not expected.");
					}
				
					if( property.IsRelational )
					{
						// find the containing filter for this axis (there has to be one) and track the child
						Expression child = axis;
						Expression parent = axis.Owner;
						while( parent != null && parent.NodeType != NodeType.Filter )
						{
							child = parent;
							parent = parent.Owner;
						}
						if( parent == null )
						{
							throw new Exception("Axis node is not contained in a Filter node.  Assumption failed.");
						}
			
						if( ((Filter)parent).Source != child ) // axis not in source of filter
						{
							filter = new Unary(UnaryOperator.Exists, filter);
						}
					}
				}

				// do the replacement
				Expression.Replace(axis, filter);
			}
			return true;
		}
Пример #2
0
		private void WriteFilterConstraints(TextWriter w, Filter filter, bool whereStarted)
		{
			// add any source constraints in a nested filter
			if( filter.Source.NodeType == NodeType.Filter )
			{
				Filter sourceFilter = (Filter)filter.Source;
				sourceFilter.Alias = filter.Alias;

				if( !whereStarted )
				{
					w.Write("\nWHERE ");
					whereStarted = true;
				}
				else
				{
					w.Write(' ');
					w.Write(GetSqlKeyword(BinaryOperator.LogicalAnd));
					w.Write(' ');
				}

				WriteSqlQuery(w, sourceFilter.Constraint);
			}

			// add the filter constraints
			if( filter.Constraint.NodeType != NodeType.Empty )
			{
				if( !whereStarted )
				{
					w.Write("\nWHERE ");
					whereStarted = true;
				}
				else
				{
					w.Write(' ');
					w.Write(GetSqlKeyword(BinaryOperator.LogicalAnd));
					w.Write(' ');
				}

				WriteSqlQuery(w, filter.Constraint);
			}
		}