/// <summary>
		/// Execute each current validator.
		/// </summary>
		internal void Validate(SqlNode node)
		{
			foreach(SqlVisitor validator in this.validators)
			{
				validator.Visit(node);
			}
		}
		internal override SqlNode Visit(SqlNode node) {
			node = base.Visit(node);
			if (node != null) {
				node.ClearSourceExpression();
			}
			return node;
		}
Esempio n. 3
0
		internal SqlColumn BubbleUp(SqlColumn col, SqlNode source)
		{
			this.match = this.GetOriginatingColumn(col);
			this.found = null;
			this.Visit(source);
			return this.found;
		}
 internal override SqlNode Visit(SqlNode node) {
     // Short-circuit when the answer is alreading known
     if (this.referencesAnyMatchingAliases) {
         return node;
     }
     return base.Visit(node);
 }
Esempio n. 5
0
 internal SqlUnion(SqlNode left, SqlNode right, bool all)
     : base(SqlNodeType.Union, right.SourceExpression)
 {
     this.Left  = left;
     this.Right = right;
     this.All   = all;
 }
Esempio n. 6
0
        private static ProviderType GetSqlType(SqlNode node)
        {
            SqlExpression exp = node as SqlExpression;

            if (exp != null)
            {
                return(exp.SqlType);
            }
            SqlSelect sel = node as SqlSelect;

            if (sel != null)
            {
                return(sel.Selection.SqlType);
            }
            SqlTable tab = node as SqlTable;

            if (tab != null)
            {
                return(tab.SqlRowType);
            }
            SqlUnion su = node as SqlUnion;

            if (su != null)
            {
                return(su.GetSqlType());
            }
            throw Error.UnexpectedNode(node.NodeType);
        }
Esempio n. 7
0
            internal override SqlNode Visit(SqlNode node) {
                if (node == null)
                    return null;

                sourceExpression = node as SqlExpression;
                if (sourceExpression != null) {
                    Type type = sourceExpression.ClrType;
                    UnwrapStack unwrap = this.UnwrapSequences;
                    while (unwrap != null) {
                        if (unwrap.Unwrap) {
                            type = TypeSystem.GetElementType(type);
                        }
                        unwrap = unwrap.Last;
                    }
                    sourceType = type;
                }
                if (sourceType != null && TypeSystem.GetNonNullableType(sourceType).IsValueType) {
                    return node; // Value types can't also have a dynamic type.
                }
                if (sourceType != null && TypeSystem.HasIEnumerable(sourceType)) {
                    return node; // Sequences can't be polymorphic.
                }

                switch (node.NodeType) {
                    case SqlNodeType.ScalarSubSelect:
                    case SqlNodeType.Multiset:
                    case SqlNodeType.Element:
                    case SqlNodeType.SearchedCase:
                    case SqlNodeType.ClientCase:
                    case SqlNodeType.SimpleCase:
                    case SqlNodeType.Member:
                    case SqlNodeType.DiscriminatedType:
                    case SqlNodeType.New:
                    case SqlNodeType.FunctionCall:
                    case SqlNodeType.MethodCall:
                    case SqlNodeType.Convert: // Object identity does not survive convert. It does survive Cast.
                        // Dig no further.
                        return node;
                    case SqlNodeType.TypeCase:
                        sourceType = ((SqlTypeCase)node).RowType.Type;
                        return node;
                    case SqlNodeType.Link:
                        sourceType = ((SqlLink)node).RowType.Type;
                        return node;
                    case SqlNodeType.Table:
                        sourceType = ((SqlTable)node).RowType.Type;
                        return node;
                    case SqlNodeType.Value:
                        SqlValue val = (SqlValue)node;
                        if (val.Value != null) {
                            // In some cases the ClrType of a Value node may
                            // differ from the actual runtime type of the value.
                            // Therefore, we ensure here that the correct type is set.
                            sourceType = val.Value.GetType();
                        }
                        return node;
                }
                return base.Visit(node);
            }
Esempio n. 8
0
		internal QueryInfo(SqlNode query, string commandText, ReadOnlyCollection<SqlParameterInfo> parameters, ResultShape resultShape, Type resultType)
		{
			this.query = query;
			this.commandText = commandText;
			this.parameters = parameters;
			this.resultShape = resultShape;
			this.resultType = resultType;
		}
Esempio n. 9
0
		internal SqlNode Deflate(SqlNode node)
		{
			node = _valueDeflator.Visit(node);
			node = _columnDeflator.Visit(node);
			node = _aliasDeflator.Visit(node);
			node = _topselectDeflator.Visit(node);
			node = _duplicateColumnDeflator.Visit(node);
			return node;
		}
		internal override SqlNode Visit(SqlNode node)
		{
			// recurse until we know we're invalid
			if(_isValid && node != null)
			{
				return base.Visit(node);
			}

			return node;
		}
		internal override SqlNode Visit(SqlNode node)
		{
			SqlExpression e = node as SqlExpression;
			if(this.hasDependency)
				return node;
			if(e != null && this.ignoreExpressions.Contains(e))
			{
				return node;
			}
			return base.Visit(node);
		}
Esempio n. 12
0
 private void Validate(SqlNode node)
 {
     if (node == null)
     {
         throw Error.ArgumentNull("node");
     }
     if (!(node is SqlExpression || node is SqlSelect || node is SqlUnion))
     {
         throw Error.UnexpectedNode(node.NodeType);
     }
 }
		internal string Format(SqlNode node, bool isDebug)
		{
			_commandStringBuilder = new StringBuilder();
			_isDebugMode = isDebug;
			_aliasMap.Clear();
			if(isDebug)
			{
				new AliasMapper(_aliasMap).Visit(node);
			}
			this.Visit(node);
			return _commandStringBuilder.ToString();
		}
Esempio n. 14
0
		/// <summary>
		/// Add an annotation to the given node.
		/// </summary>
		internal void Add(SqlNode node, SqlNodeAnnotation annotation)
		{
			List<SqlNodeAnnotation> list = null;

			if(!this.annotationMap.TryGetValue(node, out list))
			{
				list = new List<SqlNodeAnnotation>();
				this.annotationMap[node] = list;
			}

			uniqueTypes[annotation.GetType()] = String.Empty;

			list.Add(annotation);
		}
Esempio n. 15
0
			internal override SqlNode Visit(SqlNode node)
			{
				if(annotations.NodeIsAnnotated(node))
				{
					foreach(SqlNodeAnnotation annotation in annotations.Get(node))
					{
						CompatibilityAnnotation ssca = annotation as CompatibilityAnnotation;
						if(ssca != null && ssca.AppliesTo(_providerMode))
						{
							reasons.Add(annotation.Message);
						}
					}
				}
				return base.Visit(node);
			}
Esempio n. 16
0
		/// <summary>
		/// Checks whether the given node is supported on the given server.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <param name="annotations">The annotations.</param>
		/// <param name="providerMode">The provider mode to check for.</param>
		internal static void ThrowIfUnsupported(SqlNode node, SqlNodeAnnotations annotations, Enum providerMode)
		{
			// Check to see whether there's at least one SqlServerCompatibilityAnnotation.
			if(annotations.HasAnnotationType(typeof(CompatibilityAnnotation)))
			{
				Visitor visitor = new Visitor(providerMode) {annotations = annotations};
				visitor.Visit(node);

				// If any messages were recorded, then throw an exception.
				if(visitor.reasons.Count > 0)
				{
					throw Error.ExpressionNotSupportedForSqlServerVersion(visitor.reasons);
				}
			}
		}
Esempio n. 17
0
		private static ProviderType GetSqlType(SqlNode node) {
			SqlExpression exp = node as SqlExpression;
			if (exp != null)
				return exp.SqlType;
			SqlSelect sel = node as SqlSelect;
			if (sel != null)
				return sel.Selection.SqlType;
			SqlTable tab = node as SqlTable;
			if (tab != null)
				return tab.SqlRowType;
			SqlUnion su = node as SqlUnion;
			if (su != null)
				return su.GetSqlType();
			throw Error.UnexpectedNode(node.NodeType);
		}
Esempio n. 18
0
		internal override SqlNode Visit(SqlNode node)
		{
			if(node == null)
			{
				return null;
			}
			SqlNode result = null;
			if(this.nodeMap.TryGetValue(node, out result))
			{
				return result;
			}
			result = base.Visit(node);
			this.nodeMap[node] = result;
			return result;
		}
Esempio n. 19
0
		internal static SqlNode Copy(SqlNode node)
		{
			if(node == null)
				return null;
			switch(node.NodeType)
			{
				case SqlNodeType.ColumnRef:
				case SqlNodeType.Value:
				case SqlNodeType.Parameter:
				case SqlNodeType.Variable:
					return node;
				default:
					return new SqlDuplicator().Duplicate(node);
			}
		}
Esempio n. 20
0
		internal override SqlNode Visit(SqlNode node) {
			SqlExpression expr = node as SqlExpression;
			if (expr != null) {
				if (this.candidates.Contains(expr)) {
					if (expr.NodeType == SqlNodeType.Column ||
						expr.NodeType == SqlNodeType.ColumnRef) {
							return expr;
						}
					else {
						return new SqlColumn(expr.ClrType, expr.SqlType, null, null, expr, expr.SourceExpression);
					}
				}
			}
			return base.Visit(node);
		}
Esempio n. 21
0
		internal override SqlNode Visit(SqlNode node) {
			SqlExpression expression = node as SqlExpression;
			if (expression != null) {
				bool saveIsBlocked = this.isBlocked;
				this.isBlocked = false;
				if (CanRecurseColumnize(expression)) {
					base.Visit(expression);
				}
				if (!this.isBlocked) {
					if (CanBeColumn(expression)) {
						this.candidates.Add(expression);
					}
					else {
						this.isBlocked = true;
					}
				}
				this.isBlocked |= saveIsBlocked;
			}
			return node;
		}
Esempio n. 22
0
		private static Type GetClrType(SqlNode node) {
			SqlTableValuedFunctionCall tvf = node as SqlTableValuedFunctionCall;
			if (tvf != null)
				return tvf.RowType.Type;
			SqlExpression exp = node as SqlExpression;
			if (exp != null) {
				if (TypeSystem.IsSequenceType(exp.ClrType))
					return TypeSystem.GetElementType(exp.ClrType);
				return exp.ClrType;
			}
			SqlSelect sel = node as SqlSelect;
			if (sel != null)
				return sel.Selection.ClrType;
			SqlTable tab = node as SqlTable;
			if (tab != null)
				return tab.RowType.Type;
			SqlUnion su = node as SqlUnion;
			if (su != null)
				return su.GetClrType();
			throw Error.UnexpectedNode(node.NodeType);
		}
Esempio n. 23
0
        private static Type GetClrType(SqlNode node)
        {
            SqlTableValuedFunctionCall tvf = node as SqlTableValuedFunctionCall;

            if (tvf != null)
            {
                return(tvf.RowType.Type);
            }
            SqlExpression exp = node as SqlExpression;

            if (exp != null)
            {
                if (TypeSystem.IsSequenceType(exp.ClrType))
                {
                    return(TypeSystem.GetElementType(exp.ClrType));
                }
                return(exp.ClrType);
            }
            SqlSelect sel = node as SqlSelect;

            if (sel != null)
            {
                return(sel.Selection.ClrType);
            }
            SqlTable tab = node as SqlTable;

            if (tab != null)
            {
                return(tab.RowType.Type);
            }
            SqlUnion su = node as SqlUnion;

            if (su != null)
            {
                return(su.GetClrType());
            }
            throw Error.UnexpectedNode(node.NodeType);
        }
		internal virtual void VisitWithParens(SqlNode node, SqlNode outer)
		{
			if(node == null)
				return;
			switch(node.NodeType)
			{
				case SqlNodeType.ColumnRef:
				case SqlNodeType.Value:
				case SqlNodeType.Member:
				case SqlNodeType.Parameter:
				case SqlNodeType.FunctionCall:
				case SqlNodeType.TableValuedFunctionCall:
				case SqlNodeType.OuterJoinedValue:
					this.Visit(node);
					break;
				case SqlNodeType.Add:
				case SqlNodeType.Mul:
				case SqlNodeType.And:
				case SqlNodeType.Or:
				case SqlNodeType.Not:
				case SqlNodeType.Not2V:
				case SqlNodeType.BitAnd:
				case SqlNodeType.BitOr:
				case SqlNodeType.BitXor:
				case SqlNodeType.BitNot:
					if(outer.NodeType != node.NodeType)
						goto default;
					this.Visit(node);
					break;

				default:
					_commandStringBuilder.Append("(");
					this.Visit(node);
					_commandStringBuilder.Append(")");
					break;
			}
		}
		internal static bool CanConvert(SqlNode node)
		{
			SqlUnary su = node as SqlUnary;
			if(su != null && IsSupportedUnary(su))
			{
				return true;
			}
			SqlNew sn = node as SqlNew;
			if(sn != null && IsSupportedNew(sn))
			{
				return true;
			}
			SqlMember sm = node as SqlMember;
			if(sm != null && IsSupportedMember(sm))
			{
				return true;
			}
			SqlMethodCall mc = node as SqlMethodCall;
			if(mc != null && (GetMethodSupport(mc) == MethodSupport.Method))
			{
				return true;
			}
			return false;
		}
		internal static SqlNode Reduce(SqlNode node, SqlNodeAnnotations annotations, Enum[] providerModesWithIncompatibilities)
		{
			Reducer r = new Reducer(providerModesWithIncompatibilities) {Annotations = annotations};
			return r.Visit(node);
		}
Esempio n. 27
0
		internal SqlNode Duplicate(SqlNode node)
		{
			return this.superDuper.Visit(node);
		}
Esempio n. 28
0
		internal KnownExpression(SqlNode node, Type type)
			: base(InternalExpressionType.Known, type) {
			this.node = node;
			}
Esempio n. 29
0
		internal bool HasSideEffect(SqlNode node)
		{
			this.hasSideEffect = false;
			this.Visit(node);
			return this.hasSideEffect;
		}
Esempio n. 30
0
 internal SqlIncludeScope(SqlNode child, Expression sourceExpression)
     : base(SqlNodeType.IncludeScope, sourceExpression)
 {
     this.child = child;
 }
		internal static bool IsDependent(SqlNode node, HashSet<SqlAlias> aliasesToCheck, HashSet<SqlExpression> ignoreExpressions)
		{
			AliasDependencyChecker v = new AliasDependencyChecker(aliasesToCheck, ignoreExpressions);
			v.Visit(node);
			return v.hasDependency;
		}
		internal bool HasRowNumber(SqlNode node)
		{
			this.rowNumberVisitor.Visit(node);
			return rowNumberVisitor.HasRowNumber;
		}
Esempio n. 33
0
        internal virtual SqlNode Visit(SqlNode node) {
            SqlNode result = null;
            if (node == null) {
                return null;
            }

            try {
                nDepth++;
                CheckRecursionDepth(500, nDepth);

                switch (node.NodeType) {
                    case SqlNodeType.Not:
                    case SqlNodeType.Not2V:
                    case SqlNodeType.Negate:
                    case SqlNodeType.BitNot:
                    case SqlNodeType.IsNull:
                    case SqlNodeType.IsNotNull:
                    case SqlNodeType.Count:
                    case SqlNodeType.LongCount:
                    case SqlNodeType.Max:
                    case SqlNodeType.Min:
                    case SqlNodeType.Sum:
                    case SqlNodeType.Avg:
                    case SqlNodeType.Stddev:
                    case SqlNodeType.Convert:
                    case SqlNodeType.ValueOf:
                    case SqlNodeType.OuterJoinedValue:
                    case SqlNodeType.ClrLength:
                        result = this.VisitUnaryOperator((SqlUnary)node);
                        break;
                    case SqlNodeType.Lift:
                        result = this.VisitLift((SqlLift)node);
                        break;
                    case SqlNodeType.Add:
                    case SqlNodeType.Sub:
                    case SqlNodeType.Mul:
                    case SqlNodeType.Div:
                    case SqlNodeType.Mod:
                    case SqlNodeType.BitAnd:
                    case SqlNodeType.BitOr:
                    case SqlNodeType.BitXor:
                    case SqlNodeType.And:
                    case SqlNodeType.Or:
                    case SqlNodeType.GE:
                    case SqlNodeType.GT:
                    case SqlNodeType.LE:
                    case SqlNodeType.LT:
                    case SqlNodeType.EQ:
                    case SqlNodeType.NE:
                    case SqlNodeType.EQ2V:
                    case SqlNodeType.NE2V:
                    case SqlNodeType.Concat:
                    case SqlNodeType.Coalesce:
                        result = this.VisitBinaryOperator((SqlBinary)node);
                        break;
                    case SqlNodeType.Between:
                        result = this.VisitBetween((SqlBetween)node);
                        break;
                    case SqlNodeType.In:
                        result = this.VisitIn((SqlIn)node);
                        break;
                    case SqlNodeType.Like:
                        result = this.VisitLike((SqlLike)node);
                        break;
                    case SqlNodeType.Treat:
                        result = this.VisitTreat((SqlUnary)node);
                        break;
                    case SqlNodeType.Alias:
                        result = this.VisitAlias((SqlAlias)node);
                        break;
                    case SqlNodeType.AliasRef:
                        result = this.VisitAliasRef((SqlAliasRef)node);
                        break;
                    case SqlNodeType.Member:
                        result = this.VisitMember((SqlMember)node);
                        break;
                    case SqlNodeType.Row:
                        result = this.VisitRow((SqlRow)node);
                        break;
                    case SqlNodeType.Column:
                        result = this.VisitColumn((SqlColumn)node);
                        break;
                    case SqlNodeType.ColumnRef:
                        result = this.VisitColumnRef((SqlColumnRef)node);
                        break;
                    case SqlNodeType.Table:
                        result = this.VisitTable((SqlTable)node);
                        break;
                    case SqlNodeType.UserQuery:
                        result = this.VisitUserQuery((SqlUserQuery)node);
                        break;
                    case SqlNodeType.StoredProcedureCall:
                        result = this.VisitStoredProcedureCall((SqlStoredProcedureCall)node);
                        break;
                    case SqlNodeType.UserRow:
                        result = this.VisitUserRow((SqlUserRow)node);
                        break;
                    case SqlNodeType.UserColumn:
                        result = this.VisitUserColumn((SqlUserColumn)node);
                        break;
                    case SqlNodeType.Multiset:
                    case SqlNodeType.ScalarSubSelect:
                    case SqlNodeType.Element:
                    case SqlNodeType.Exists:
                        result = this.VisitSubSelect((SqlSubSelect)node);
                        break;
                    case SqlNodeType.Join:
                        result = this.VisitJoin((SqlJoin)node);
                        break;
                    case SqlNodeType.Select:
                        result = this.VisitSelect((SqlSelect)node);
                        break;
                    case SqlNodeType.Parameter:
                        result = this.VisitParameter((SqlParameter)node);
                        break;
                    case SqlNodeType.New:
                        result = this.VisitNew((SqlNew)node);
                        break;
                    case SqlNodeType.Link:
                        result = this.VisitLink((SqlLink)node);
                        break;
                    case SqlNodeType.ClientQuery:
                        result = this.VisitClientQuery((SqlClientQuery)node);
                        break;
                    case SqlNodeType.JoinedCollection:
                        result = this.VisitJoinedCollection((SqlJoinedCollection)node);
                        break;
                    case SqlNodeType.Value:
                        result = this.VisitValue((SqlValue)node);
                        break;
                    case SqlNodeType.ClientArray:
                        result = this.VisitClientArray((SqlClientArray)node);
                        break;
                    case SqlNodeType.Insert:
                        result = this.VisitInsert((SqlInsert)node);
                        break;
                    case SqlNodeType.Update:
                        result = this.VisitUpdate((SqlUpdate)node);
                        break;
                    case SqlNodeType.Delete:
                        result = this.VisitDelete((SqlDelete)node);
                        break;
                    case SqlNodeType.MemberAssign:
                        result = this.VisitMemberAssign((SqlMemberAssign)node);
                        break;
                    case SqlNodeType.Assign:
                        result = this.VisitAssign((SqlAssign)node);
                        break;
                    case SqlNodeType.Block:
                        result = this.VisitBlock((SqlBlock)node);
                        break;
                    case SqlNodeType.SearchedCase:
                        result = this.VisitSearchedCase((SqlSearchedCase)node);
                        break;
                    case SqlNodeType.ClientCase:
                        result = this.VisitClientCase((SqlClientCase)node);
                        break;
                    case SqlNodeType.SimpleCase:
                        result = this.VisitSimpleCase((SqlSimpleCase)node);
                        break;
                    case SqlNodeType.TypeCase:
                        result = this.VisitTypeCase((SqlTypeCase)node);
                        break;
                    case SqlNodeType.Union:
                        result = this.VisitUnion((SqlUnion)node);
                        break;
                    case SqlNodeType.ExprSet:
                        result = this.VisitExprSet((SqlExprSet)node);
                        break;
                    case SqlNodeType.Variable:
                        result = this.VisitVariable((SqlVariable)node);
                        break;
                    case SqlNodeType.DoNotVisit:
                        result = this.VisitDoNotVisit((SqlDoNotVisitExpression)node);
                        break;
                    case SqlNodeType.OptionalValue:
                        result = this.VisitOptionalValue((SqlOptionalValue)node);
                        break;
                    case SqlNodeType.FunctionCall:
                        result = this.VisitFunctionCall((SqlFunctionCall)node);
                        break;
                    case SqlNodeType.TableValuedFunctionCall:
                        result = this.VisitTableValuedFunctionCall((SqlTableValuedFunctionCall)node);
                        break;
                    case SqlNodeType.MethodCall:
                        result = this.VisitMethodCall((SqlMethodCall)node);
                        break;
                    case SqlNodeType.Nop:
                        result = this.VisitNop((SqlNop)node);
                        break;
                    case SqlNodeType.SharedExpression:
                        result = this.VisitSharedExpression((SqlSharedExpression)node);
                        break;
                    case SqlNodeType.SharedExpressionRef:
                        result = this.VisitSharedExpressionRef((SqlSharedExpressionRef)node);
                        break;
                    case SqlNodeType.SimpleExpression:
                        result = this.VisitSimpleExpression((SqlSimpleExpression)node);
                        break;
                    case SqlNodeType.Grouping:
                        result = this.VisitGrouping((SqlGrouping)node);
                        break;
                    case SqlNodeType.DiscriminatedType:
                        result = this.VisitDiscriminatedType((SqlDiscriminatedType)node);
                        break;
                    case SqlNodeType.DiscriminatorOf:
                        result = this.VisitDiscriminatorOf((SqlDiscriminatorOf)node);
                        break;
                    case SqlNodeType.ClientParameter:
                        result = this.VisitClientParameter((SqlClientParameter)node);
                        break;
                    case SqlNodeType.RowNumber:
                        result = this.VisitRowNumber((SqlRowNumber)node);
                        break;
                    case SqlNodeType.IncludeScope:
                        result = this.VisitIncludeScope((SqlIncludeScope)node);
                        break;
                    default:
                        throw Error.UnexpectedNode(node);
                }
            } finally {
                this.nDepth--;
            }

            return result;
        }
		internal SqlNode Rewrite(SqlNode node)
		{
			return this.visitor.Visit(node);
		}
Esempio n. 35
0
		internal SqlNode Multiplex(SqlNode node)
		{
			return this._multiSetMultiPlexor.Visit(node);
		}