public bool VisitExprDerivedTableQuery(ExprDerivedTableQuery expr, TCtx arg) { var res = this.Visit(expr, "DerivedTableQuery", arg, out var argOut) && this.Accept("Query", expr.Query, argOut) && this.Accept("Alias", expr.Alias, argOut) && this.Accept("Columns", expr.Columns, argOut); this._visitor.EndVisitExpr(expr, arg); return(res); }
public bool VisitExprDerivedTableQuery(ExprDerivedTableQuery exprDerivedTableQuery, IExpr?parent) { this.AcceptPar('(', exprDerivedTableQuery.Query, ')', exprDerivedTableQuery); exprDerivedTableQuery.Alias.Accept(this, exprDerivedTableQuery); if (exprDerivedTableQuery.Columns != null) { exprDerivedTableQuery.Columns.AssertNotEmpty("List of columns in a derived table with values literals cannot be empty"); var selectedColumns = exprDerivedTableQuery.Query.GetOutputColumnNames(); if (selectedColumns.Count != exprDerivedTableQuery.Columns.Count) { throw new SqExpressException("Number of declared columns does not match to number of selected columns in the derived table sub query"); } bool allMatch = true; for (int i = 0; i < selectedColumns.Count; i++) { if (!string.Equals(selectedColumns[i], ((IExprNamedSelecting)exprDerivedTableQuery.Columns[i]).OutputName)) { allMatch = false; break; } } if (!allMatch) { this.AcceptListComaSeparatedPar('(', exprDerivedTableQuery.Columns, ')', exprDerivedTableQuery); } } return(true); }
public static ExprDerivedTableQuery WithColumns(this ExprDerivedTableQuery original, IReadOnlyList <ExprColumnName>?newColumns) => new ExprDerivedTableQuery(query: original.Query, alias: original.Alias, columns: newColumns);
public static ExprDerivedTableQuery WithAlias(this ExprDerivedTableQuery original, ExprTableAlias newAlias) => new ExprDerivedTableQuery(query: original.Query, alias: newAlias, columns: original.Columns);
public static ExprDerivedTableQuery WithQuery(this ExprDerivedTableQuery original, IExprSubQuery newQuery) => new ExprDerivedTableQuery(query: newQuery, alias: original.Alias, columns: original.Columns);