Пример #1
0
 protected override bool ForceParenthesesForQueryExpressionPart(IExprSubQuery subQuery)
 {
     return(subQuery switch
     {
         ExprQuerySpecification specification => !ReferenceEquals(specification.Top, null),
         _ => true
     });
Пример #2
0
        public bool VisitExprQuerySpecification(ExprQuerySpecification expr, TCtx arg)
        {
            var res = this.Visit(expr, "QuerySpecification", arg, out var argOut) && this.Accept("SelectList", expr.SelectList, argOut) && this.Accept("Top", expr.Top, argOut) && this.Accept("From", expr.From, argOut) && this.Accept("Where", expr.Where, argOut) && this.Accept("GroupBy", expr.GroupBy, argOut);

            this.VisitPlainProperty("Distinct", expr.Distinct, argOut);
            this._visitor.EndVisitExpr(expr, arg);
            return(res);
        }
Пример #3
0
        public static ExprQuerySpecification WithCrossJoin(this ExprQuerySpecification querySpecification, IExprTableSource tableSource)
        {
            if (querySpecification.From == null)
            {
                throw new SqExpressException("Query Specification \"From\" cannot be null");
            }

            var newJoin = new ExprCrossedTable(querySpecification.From, tableSource);

            return(querySpecification.WithFrom(newJoin));
        }
Пример #4
0
        private static ExprQuerySpecification JoinQuerySpecification(ExprJoinedTable.ExprJoinType exprJoinType,
                                                                     ExprQuerySpecification querySpecification, IExprTableSource tableSource, ExprBoolean @on)
        {
            if (querySpecification.From == null)
            {
                throw new SqExpressException("Query Specification \"From\" cannot be null");
            }

            var newJoin = new ExprJoinedTable(querySpecification.From, exprJoinType, tableSource, on);

            return(querySpecification.WithFrom(newJoin));
        }
Пример #5
0
        public bool VisitExprQuerySpecification(ExprQuerySpecification exprQuerySpecification, IExpr?parent)
        {
            this.Builder.Append("SELECT ");
            if (exprQuerySpecification.Distinct)
            {
                this.Builder.Append("DISTINCT ");
            }
            if (!ReferenceEquals(exprQuerySpecification.Top, null))
            {
                this.AppendSelectTop(exprQuerySpecification.Top, exprQuerySpecification);
            }

            this.AcceptListComaSeparated(exprQuerySpecification.SelectList, exprQuerySpecification);

            if (exprQuerySpecification.From != null)
            {
                this.Builder.Append(" FROM ");
                exprQuerySpecification.From.Accept(this, exprQuerySpecification);
            }

            if (exprQuerySpecification.Where != null)
            {
                this.Builder.Append(" WHERE ");
                exprQuerySpecification.Where.Accept(this, exprQuerySpecification);
            }

            if (exprQuerySpecification.GroupBy != null)
            {
                this.Builder.Append(" GROUP BY ");
                this.AcceptListComaSeparated(exprQuerySpecification.GroupBy, exprQuerySpecification);
            }

            if (!ReferenceEquals(exprQuerySpecification.Top, null) && !(parent is ExprSelect) && !(parent is ExprSelectOffsetFetch))
            {
                //For non T-SQL (PostgresSQL, My SQL)
                this.AppendSelectLimit(exprQuerySpecification.Top, exprQuerySpecification);
            }

            return(true);
        }
Пример #6
0
 public static ExprQuerySpecification WithSelectList(this ExprQuerySpecification original, SelectingProxy selection, params SelectingProxy[] selections)
 => new ExprQuerySpecification(selectList: Helpers.Combine(selection, selections, SelectingProxy.MapSelectionProxy), top: original.Top, from: original.From, where : original.Where, groupBy : original.GroupBy, distinct : original.Distinct);
Пример #7
0
 public static ExprQuerySpecification WithFullJoin(this ExprQuerySpecification querySpecification, IExprTableSource tableSource, ExprBoolean on)
 => JoinQuerySpecification(ExprJoinedTable.ExprJoinType.Full, querySpecification, tableSource, on);
Пример #8
0
 public static ExprQuerySpecification WithDistinct(this ExprQuerySpecification original, Boolean newDistinct)
 => new ExprQuerySpecification(selectList: original.SelectList, top: original.Top, from: original.From, where : original.Where, groupBy : original.GroupBy, distinct : newDistinct);
Пример #9
0
 public static ExprQuerySpecification WithGroupBy(this ExprQuerySpecification original, IReadOnlyList <ExprColumn>?newGroupBy)
 => new ExprQuerySpecification(selectList: original.SelectList, top: original.Top, from: original.From, where : original.Where, groupBy : newGroupBy, distinct : original.Distinct);
Пример #10
0
 public static ExprQuerySpecification WithWhere(this ExprQuerySpecification original, ExprBoolean?newWhere)
 => new ExprQuerySpecification(selectList: original.SelectList, top: original.Top, from: original.From, where : newWhere, groupBy : original.GroupBy, distinct : original.Distinct);
Пример #11
0
 public static ExprQuerySpecification WithFrom(this ExprQuerySpecification original, IExprTableSource?newFrom)
 => new ExprQuerySpecification(selectList: original.SelectList, top: original.Top, from: newFrom, where : original.Where, groupBy : original.GroupBy, distinct : original.Distinct);
Пример #12
0
 public static ExprQuerySpecification WithTop(this ExprQuerySpecification original, ExprValue?newTop)
 => new ExprQuerySpecification(selectList: original.SelectList, top: newTop, from: original.From, where : original.Where, groupBy : original.GroupBy, distinct : original.Distinct);
Пример #13
0
 public static ExprQuerySpecification WithSelectList(this ExprQuerySpecification original, IReadOnlyList <IExprSelecting> newSelectList)
 => new ExprQuerySpecification(selectList: newSelectList, top: original.Top, from: original.From, where : original.Where, groupBy : original.GroupBy, distinct : original.Distinct);