Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 public static ExprDerivedTableQuery WithColumns(this ExprDerivedTableQuery original, IReadOnlyList <ExprColumnName>?newColumns)
 => new ExprDerivedTableQuery(query: original.Query, alias: original.Alias, columns: newColumns);
Exemple #4
0
 public static ExprDerivedTableQuery WithAlias(this ExprDerivedTableQuery original, ExprTableAlias newAlias)
 => new ExprDerivedTableQuery(query: original.Query, alias: newAlias, columns: original.Columns);
Exemple #5
0
 public static ExprDerivedTableQuery WithQuery(this ExprDerivedTableQuery original, IExprSubQuery newQuery)
 => new ExprDerivedTableQuery(query: newQuery, alias: original.Alias, columns: original.Columns);