FindExpression() public method

public FindExpression ( ObjectName alias ) : SqlExpression
alias ObjectName
return SqlExpression
Esempio n. 1
0
        private int ResolveGroupBy(SqlQueryExpression queryExpression, QueryExpressionFrom queryFrom, IRequest context, out ObjectName[] columnNames, out IList <SqlExpression> expressions)
        {
            var groupBy = queryExpression.GroupBy == null
                                ? new List <SqlExpression>(0)
                                : queryExpression.GroupBy.ToList();
            var groupBySize = groupBy.Count;

            expressions = new List <SqlExpression>();
            columnNames = new ObjectName[groupBySize];

            for (int i = 0; i < groupBySize; i++)
            {
                var expression = groupBy[i];

                // Prepare the group by expression
                expression = expression.Prepare(queryFrom.ExpressionPreparer);

                var columnName = expression.AsReferenceName();
                if (columnName != null)
                {
                    expression = queryFrom.FindExpression(columnName);
                }

                if (expression != null)
                {
                    if (expression.HasAggregate(context))
                    {
                        throw new InvalidOperationException(String.Format("Aggregate expression '{0}' is not allowed in a GROUP BY clause", expression));
                    }

                    expressions.Add(expression);
                    columnName = new ObjectName(FunctionTableName, String.Format("#GROUPBY-{0}", expressions.Count - 1));
                }

                columnNames[i] = columnName;
            }

            return(groupBySize);
        }
Esempio n. 2
0
        private int ResolveGroupBy(SqlQueryExpression queryExpression, QueryExpressionFrom queryFrom, IQueryContext context, out ObjectName[] columnNames, out IList<SqlExpression> expressions)
        {
            var groupBy = queryExpression.GroupBy == null
                ? new List<SqlExpression>(0)
                : queryExpression.GroupBy.ToList();
            var groupBySize = groupBy.Count;

            expressions = new List<SqlExpression>();
            columnNames = new ObjectName[groupBySize];

            for (int i = 0; i < groupBySize; i++) {
                var expression = groupBy[i];

                // Prepare the group by expression
                expression = expression.Prepare(queryFrom.ExpressionPreparer);

                var columnName = expression.AsReferenceName();
                if (columnName != null)
                    expression = queryFrom.FindExpression(columnName);

                if (expression != null) {
                    if (expression.HasAggregate(context))
                        throw new InvalidOperationException(String.Format("Aggregate expression '{0}' is not allowed in a GROUP BY clause", expression));

                    expressions.Add(expression);
                    columnName = new ObjectName(FunctionTableName, String.Format("#GROUPBY-{0}", expressions.Count -1));
                }

                columnNames[i] = columnName;
            }

            return groupBySize;
        }