Beispiel #1
0
 // Methods
 internal SqlClientQuery(SqlSubSelect subquery)
     : base(SqlNodeType.ClientQuery, subquery.ClrType, subquery.SqlType, subquery.SourceExpression)
 {
     this.query      = subquery;
     this.arguments  = new List <SqlExpression>();
     this.parameters = new List <SqlParameter>();
 }
Beispiel #2
0
            internal override SqlExpression VisitSubSelect(SqlSubSelect ss)
            {
                List <SqlOrderExpression> orders = this.orders;

                this.orders = new List <SqlOrderExpression>();
                base.VisitSubSelect(ss);
                this.orders = orders;
                return(ss);
            }
Beispiel #3
0
 internal override SqlExpression VisitScalarSubSelect(SqlSubSelect ss)
 {
     base.VisitScalarSubSelect(ss);
     if (ss.Select.Row.Columns.Count > 0)
     {
         ss.Select.Row.Columns[0].Name = "";
     }
     return(ss);
 }
Beispiel #4
0
            internal override SqlExpression VisitSubSelect(SqlSubSelect ss)
            {
                Scope current = this.current;

                this.current = null;
                SqlExpression expression = base.VisitSubSelect(ss);

                this.current = current;
                return(expression);
            }
Beispiel #5
0
            internal override SqlExpression VisitSubSelect(SqlSubSelect ss)
            {
                SqlExpression expression;
                bool          isTopLevel = this.isTopLevel;

                try
                {
                    expression = base.VisitSubSelect(ss);
                }
                finally
                {
                    this.isTopLevel = isTopLevel;
                }
                return(expression);
            }
Beispiel #6
0
        // Methods
        internal static SqlClientQuery Extract(SqlSubSelect subquery, IEnumerable <SqlParameter> parentParameters, SqlIdentifier sqlIdentity)
        {
            var query = new SqlClientQuery(subquery);

            if (parentParameters != null)
            {
                //query.Parameters.AddRange(parentParameters);
                foreach (var parameter in parentParameters)
                {
                    query.Parameters.Add(parameter);
                }
            }
            var visitor = new Visitor(query.Arguments, query.Parameters, sqlIdentity);

            query.Query = (SqlSubSelect)visitor.Visit(subquery);
            return(query);
        }
Beispiel #7
0
        internal virtual SqlExpression VisitSubSelect(SqlSubSelect ss)
        {
            switch (ss.NodeType)
            {
            case SqlNodeType.Element:
                return(this.VisitElement(ss));

            case SqlNodeType.Exists:
                return(this.VisitExists(ss));

            case SqlNodeType.Multiset:
                return(this.VisitMultiset(ss));

            case SqlNodeType.ScalarSubSelect:
                return(this.VisitScalarSubSelect(ss));
            }
            throw Error.UnexpectedNode(ss.NodeType);
        }
Beispiel #8
0
            internal override SqlExpression VisitExists(SqlSubSelect ss)
            {
                SqlExpression expression;
                bool          isTopLevel = this.isTopLevel;

                this.isTopLevel = false;
                bool canJoin = this.canJoin;

                this.canJoin = false;
                try
                {
                    expression = base.VisitExists(ss);
                }
                finally
                {
                    this.isTopLevel = isTopLevel;
                    this.canJoin    = canJoin;
                }
                return(expression);
            }
Beispiel #9
0
            internal override SqlExpression VisitScalarSubSelect(SqlSubSelect ss)
            {
                SqlExpression expression;
                bool          isTopLevel = this.isTopLevel;

                this.isTopLevel = false;
                bool forceReferenceAll = this.forceReferenceAll;

                this.forceReferenceAll = true;
                try
                {
                    expression = base.VisitScalarSubSelect(ss);
                }
                finally
                {
                    this.isTopLevel        = isTopLevel;
                    this.forceReferenceAll = forceReferenceAll;
                }
                return(expression);
            }
Beispiel #10
0
 internal override SqlExpression VisitMultiset(SqlSubSelect sms)
 {
     if (((((this.options & SqlMultiplexer.Options.EnableBigJoin) != SqlMultiplexer.Options.None) && !this.hasBigJoin) &&
          (this.canJoin && this.isTopLevel)) && (((this.outerSelect != null) && !MultisetChecker.HasMultiset(sms.Select.Selection)) &&
                                                 BigJoinChecker.CanBigJoin(sms.Select)))
     {
         sms.Select = this.VisitSelect(sms.Select);
         SqlAlias right = new SqlAlias(sms.Select);
         SqlJoin  join  = new SqlJoin(SqlJoinType.OuterApply, this.outerSelect.From, right, null, sms.SourceExpression);
         this.outerSelect.From         = join;
         this.outerSelect.OrderingType = SqlOrderingType.Always;
         SqlExpression expression = (SqlExpression)SqlDuplicator.Copy(sms.Select.Selection);
         SqlSelect     node       = (SqlSelect)SqlDuplicator.Copy(sms.Select);
         SqlAlias      from       = new SqlAlias(node);
         SqlSelect     select     = new SqlSelect(this.sql.Unary(SqlNodeType.Count, null, sms.SourceExpression), from, sms.SourceExpression);
         select.OrderingType = SqlOrderingType.Never;
         SqlExpression       count   = this.sql.SubSelect(SqlNodeType.ScalarSubSelect, select);
         SqlJoinedCollection joineds = new SqlJoinedCollection(sms.ClrType, sms.SqlType, expression, count, sms.SourceExpression);
         this.hasBigJoin = true;
         return(joineds);
     }
     return(QueryExtractor.Extract(sms, this.parentParameters, sqlIdentity));
 }
Beispiel #11
0
 internal override SqlExpression VisitSubSelect(SqlSubSelect ss)
 {
     return((SqlExpression) new SqlDuplicator().Duplicate(ss));
 }
Beispiel #12
0
 internal override SqlExpression VisitElement(SqlSubSelect elem)
 {
     return(QueryExtractor.Extract(elem, this.parentParameters, sqlIdentity));
 }
Beispiel #13
0
 internal override SqlExpression VisitElement(SqlSubSelect elem)
 {
     return(this.VisitMultiset(elem));
 }
Beispiel #14
0
 internal override SqlExpression VisitMultiset(SqlSubSelect sms)
 {
     return(new SqlSubSelect(sms.NodeType, sms.ClrType, sms.SqlType, (SqlSelect)this.Visit(sms.Select)));
 }
Beispiel #15
0
 internal override SqlExpression VisitExists(SqlSubSelect sqlExpr)
 {
     return(new SqlSubSelect(sqlExpr.NodeType, sqlExpr.ClrType, sqlExpr.SqlType, (SqlSelect)this.Visit(sqlExpr.Select)));
 }
Beispiel #16
0
 internal virtual SqlExpression VisitMultiset(SqlSubSelect sms)
 {
     sms.Select = this.VisitSequence(sms.Select);
     return(sms);
 }
Beispiel #17
0
 internal virtual SqlExpression VisitScalarSubSelect(SqlSubSelect ss)
 {
     ss.Select = this.VisitSequence(ss.Select);
     return(ss);
 }
Beispiel #18
0
 internal virtual SqlExpression VisitExists(SqlSubSelect sqlExpr)
 {
     sqlExpr.Select = this.VisitSequence(sqlExpr.Select);
     return(sqlExpr);
 }
Beispiel #19
0
 internal virtual SqlExpression VisitElement(SqlSubSelect elem)
 {
     elem.Select = this.VisitSequence(elem.Select);
     return(elem);
 }
Beispiel #20
0
 internal override SqlExpression VisitScalarSubSelect(SqlSubSelect ss)
 {
     return(new SqlSubSelect(SqlNodeType.ScalarSubSelect, ss.ClrType, ss.SqlType, this.VisitSequence(ss.Select)));
 }
Beispiel #21
0
 internal override SqlExpression VisitScalarSubSelect(SqlSubSelect ss)
 {
     base.VisitScalarSubSelect(ss);
     ss.SetSqlType(ss.Select.Selection.SqlType);
     return(ss);
 }
Beispiel #22
0
 internal override SqlExpression VisitSubSelect(SqlSubSelect ss)
 {
     return(ss);
 }