protected override bool ForceParenthesesForQueryExpressionPart(IExprSubQuery subQuery) { return(subQuery switch { ExprQuerySpecification specification => !ReferenceEquals(specification.Top, null), _ => true });
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); }
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)); }
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)); }
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); }
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);
public static ExprQuerySpecification WithFullJoin(this ExprQuerySpecification querySpecification, IExprTableSource tableSource, ExprBoolean on) => JoinQuerySpecification(ExprJoinedTable.ExprJoinType.Full, querySpecification, tableSource, on);
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);
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);
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);
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);
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);
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);