Esempio n. 1
0
            internal override SqlNode Visit(SqlNode node)
            {
                SqlExpression expr = node as SqlExpression;

                if (expr != null)
                {
                    bool isBlocked = this.isBlocked;
                    this.isBlocked = false;
                    if (CanRecurseColumnize(expr))
                    {
                        base.Visit(expr);
                    }
                    if (!this.isBlocked)
                    {
                        if (!IsClientOnly(expr) && (expr.NodeType != SqlNodeType.Column) && expr.SqlType.CanBeColumn &&
                            (this.fnCanBeColumn == null || this.fnCanBeColumn(expr)))
                        {
                            this.candidates.Add(expr);
                        }
                        else
                        {
                            this.isBlocked = true;
                        }
                    }
                    this.isBlocked |= isBlocked;
                }
                return(node);
            }
Esempio n. 2
0
        private List <SqlParameterInfo> ParameterizeInternal(SqlNode node)
        {
            var visitor = new Visitor(this);

            visitor.Visit(node);
            return(new List <SqlParameterInfo>(visitor.currentParams));
        }
Esempio n. 3
0
        // Methods
        internal static Dictionary <SqlAlias, bool> Gather(SqlNode node)
        {
            Gatherer gatherer = new Gatherer();

            gatherer.Visit(node);
            return(gatherer.Produced);
        }
Esempio n. 4
0
 // Methods
 internal SqlUnion(SqlNode left, SqlNode right, bool all)
     : base(SqlNodeType.Union, right.SourceExpression)
 {
     this.Left  = left;
     this.Right = right;
     this.All   = all;
 }
Esempio n. 5
0
        internal List <SqlNodeAnnotation> Get(SqlNode node)
        {
            List <SqlNodeAnnotation> list = null;

            this.annotationMap.TryGetValue(node, out list);
            return(list);
        }
Esempio n. 6
0
 internal void Validate(SqlNode node)
 {
     foreach (SqlVisitor visitor in validators)
     {
         visitor.Visit(node);
     }
 }
Esempio n. 7
0
            internal override SqlExpression VisitAliasRef(SqlAliasRef aref)
            {
                SqlNode node = aref.Alias.Node;

                if ((node is SqlTable) || (node is SqlTableValuedFunctionCall))
                {
                    return(aref);
                }
                SqlUnion union = node as SqlUnion;

                if (union != null)
                {
                    return(this.ExpandUnion(union));
                }
                SqlSelect select = node as SqlSelect;

                if (select != null)
                {
                    return(this.VisitExpression(select.Selection));
                }
                SqlExpression exp = node as SqlExpression;

                if (exp == null)
                {
                    throw Error.CouldNotHandleAliasRef(node.NodeType);
                }
                return(this.VisitExpression(exp));
            }
Esempio n. 8
0
            private void GatherUnionExpressions(SqlNode node, IList <SqlExpression> exprs)
            {
                SqlUnion union = node as SqlUnion;

                if (union != null)
                {
                    this.GatherUnionExpressions(union.Left, exprs);
                    this.GatherUnionExpressions(union.Right, exprs);
                }
                else
                {
                    SqlSelect select = node as SqlSelect;
                    if (select != null)
                    {
                        SqlAliasRef selection = select.Selection as SqlAliasRef;
                        if (selection != null)
                        {
                            this.GatherUnionExpressions(selection.Alias.Node, exprs);
                        }
                        else
                        {
                            exprs.Add(select.Selection);
                        }
                    }
                }
            }
Esempio n. 9
0
        // Methods
        internal static SqlNode Reduce(SqlNode node, SqlNodeAnnotations annotations)
        {
            Reducer reducer = new Reducer();

            reducer.Annotations = annotations;
            return(reducer.Visit(node));
        }
Esempio n. 10
0
        private static IProviderType GetSqlType(SqlNode node)
        {
            SqlExpression expression = node as SqlExpression;

            if (expression != null)
            {
                return(expression.SqlType);
            }
            SqlSelect select = node as SqlSelect;

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

            if (table != null)
            {
                return(table.SqlRowType);
            }
            SqlUnion union = node as SqlUnion;

            if (union == null)
            {
                throw Error.UnexpectedNode(node.NodeType);
            }
            return(union.GetSqlType());
        }
Esempio n. 11
0
        // Methods
        internal static bool ReferencesAny(SqlNode node, IEnumerable <SqlAlias> aliases)
        {
            Visitor visitor = new Visitor();

            visitor.aliases = aliases;
            visitor.Visit(node);
            return(visitor.referencesAnyMatchingAliases);
        }
Esempio n. 12
0
            // Fields

            // Methods
            internal QueryInfo(SqlNode query, string commandText, ReadOnlyCollection <SqlParameterInfo> parameters, SqlProvider.ResultShape resultShape, Type resultType)
            {
                this.Query       = query;
                this.CommandText = commandText;
                this.Parameters  = parameters;
                this.ResultShape = resultShape;
                this.ResultType  = resultType;
            }
Esempio n. 13
0
            // Methods
            internal static bool IsDependent(SqlNode node, Dictionary <SqlAlias, bool> aliasesToCheck,
                                             Dictionary <SqlExpression, bool> ignoreExpressions)
            {
                Visitor visitor = new Visitor(aliasesToCheck, ignoreExpressions);

                visitor.Visit(node);
                return(visitor.hasDependency);
            }
Esempio n. 14
0
 internal bool NodeIsAnnotated(SqlNode node)
 {
     if (node == null)
     {
         return(false);
     }
     return(this.annotationMap.ContainsKey(node));
 }
Esempio n. 15
0
 internal override SqlNode Visit(SqlNode node)
 {
     if (this.IsValid && (node != null))
     {
         return(base.Visit(node));
     }
     return(node);
 }
Esempio n. 16
0
 // Methods
 internal override SqlNode Visit(SqlNode node)
 {
     if (this.referencesAnyMatchingAliases)
     {
         return(node);
     }
     return(base.Visit(node));
 }
Esempio n. 17
0
 internal override SqlNode Visit(SqlNode node)
 {
     node = base.Visit(node);
     if (node != null)
     {
         node.ClearSourceExpression();
     }
     return(node);
 }
Esempio n. 18
0
 internal SqlNode Deflate(SqlNode node)
 {
     node = this.vDeflator.Visit(node);
     node = this.cDeflator.Visit(node);
     node = this.aDeflator.Visit(node);
     node = this.tsDeflator.Visit(node);
     node = this.dupColumnDeflator.Visit(node);
     return(node);
 }
Esempio n. 19
0
            internal override SqlNode VisitUnion(SqlUnion su)
            {
                Scope current = this.current;

                this.current = null;
                SqlNode node = base.VisitUnion(su);

                this.current = current;
                return(node);
            }
Esempio n. 20
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);
     }
 }
Esempio n. 21
0
        // Methods
        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;
            }
            this.uniqueTypes[annotation.GetType()] = string.Empty;
            list.Add(annotation);
        }
Esempio n. 22
0
                internal override SqlNode Visit(SqlNode node)
                {
                    SqlExpression key = node as SqlExpression;

                    if (this.hasDependency)
                    {
                        return(node);
                    }
                    if ((key != null) && this.ignoreExpressions.ContainsKey(key))
                    {
                        return(node);
                    }
                    return(base.Visit(node));
                }
Esempio n. 23
0
            internal override SqlNode Visit(SqlNode node)
            {
                SqlExpression item = node as SqlExpression;

                if ((item == null) || !this.candidates.Contains(item))
                {
                    return(base.Visit(node));
                }
                if ((item.NodeType != SqlNodeType.Column) && (item.NodeType != SqlNodeType.ColumnRef))
                {
                    return(new SqlColumn(item.ClrType, item.SqlType, null, null, item, item.SourceExpression));
                }
                return(item);
            }
Esempio n. 24
0
 // Methods
 internal static void ThrowIfUnsupported(SqlNode node, SqlNodeAnnotations annotations,
                                         SqlProvider.ProviderMode provider)
 {
     if (annotations.HasAnnotationType(typeof(SqlServerCompatibilityAnnotation)))
     {
         Visitor visitor = new Visitor(provider);
         visitor.annotations = annotations;
         visitor.Visit(node);
         if (visitor.reasons.Count > 0)
         {
             throw Error.ExpressionNotSupportedForSqlServerVersion(visitor.reasons);
         }
     }
 }
Esempio n. 25
0
            internal override SqlNode Visit(SqlNode node)
            {
                if (node == null)
                {
                    return(null);
                }
                SqlNode node2 = null;

                if (!this.nodeMap.TryGetValue(node, out node2))
                {
                    node2 = base.Visit(node);
                    this.nodeMap[node] = node2;
                }
                return(node2);
            }
Esempio n. 26
0
 internal override SqlNode Visit(SqlNode node)
 {
     if (annotations.NodeIsAnnotated(node))
     {
         foreach (SqlNodeAnnotation annotation in annotations.Get(node))
         {
             SqlServerCompatibilityAnnotation annotation2 = annotation as SqlServerCompatibilityAnnotation;
             if ((annotation2 != null) && annotation2.AppliesTo(provider))
             {
                 reasons.Add(annotation.Message);
             }
         }
     }
     return(base.Visit(node));
 }
Esempio n. 27
0
        // Methods
        internal static bool CanConvert(SqlNode node)
        {
            var bo = node as SqlBinary;

            if ((bo == null) || (!IsCompareToValue(bo) && !IsVbCompareStringEqualsValue(bo)))
            {
                var m = node as SqlMember;
                if ((m == null) || !IsSupportedMember(m))
                {
                    var mc = node as SqlMethodCall;
                    if ((mc == null) || (!IsSupportedMethod(mc) && !IsSupportedVbHelperMethod(mc)))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 28
0
        ReadOnlyCollection <ReadOnlyCollection <SqlParameterInfo> > ISqlParameterizer.ParameterizeBlock(SqlBlock block)
        {
            var item = new SqlParameterInfo(new SqlParameter(typeof(int), typeProvider.From(typeof(int)),
                                                             "@ROWCOUNT", block.SourceExpression));
            var list  = new List <ReadOnlyCollection <SqlParameterInfo> >();
            int num   = 0;
            int count = block.Statements.Count;

            while (num < count)
            {
                SqlNode node = block.Statements[num];
                List <SqlParameterInfo> list2 = this.ParameterizeInternal(node);
                if (num > 0)
                {
                    list2.Add(item);
                }
                list.Add(list2.AsReadOnly());
                num++;
            }
            return(list.AsReadOnly());
        }
Esempio n. 29
0
        private static Type GetClrType(SqlNode node)
        {
            SqlTableValuedFunctionCall call = node as SqlTableValuedFunctionCall;

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

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

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

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

            if (union == null)
            {
                throw Error.UnexpectedNode(node.NodeType);
            }
            return(union.GetClrType());
        }
Esempio n. 30
0
        internal static SqlNode Copy(SqlNode node)
        {
            if (node == null)
            {
                return(null);
            }
            SqlNodeType nodeType = node.NodeType;

            if (nodeType != SqlNodeType.ColumnRef)
            {
                switch (nodeType)
                {
                case SqlNodeType.Variable:
                case SqlNodeType.Value:
                    return(node);

                case SqlNodeType.Parameter:
                    return(node);
                }
                return(new SqlDuplicator().Duplicate(node));
            }
            return(node);
        }