Beispiel #1
0
        protected override Statement Prepare(IQueryContext context)
        {
            var selectStatement = new SelectStatement {
                SelectExpression = SelectExpression,
                OrderBy          = OrderBy
            };

            // check to see if the construct is the special one for
            // selecting the latest IDENTITY value from a table
            if (IsIdentitySelect(selectStatement.SelectExpression))
            {
                selectStatement.SelectExpression.Columns.RemoveAt(0);
                FromTable fromTable = ((IList <FromTable>)selectStatement.SelectExpression.From.AllTables)[0];
                var       idExp     = Expression.FunctionCall("identity", Expression.Constant(DataObject.String(fromTable.Name.ToString())));
                selectStatement.SelectExpression.Columns.Add(new SelectColumn(idExp));
            }

            if (selectStatement.SelectExpression.Into != null)
            {
                selectStatement.intoClause = selectStatement.SelectExpression.Into;
            }

            // Generate the TableExpressionFromSet hierarchy for the expression,
            TableExpressionFromSet fromSet = Planner.GenerateFromSet(selectStatement.SelectExpression, context.Connection);

            // Form the plan
            selectStatement.Plan = Planner.FormQueryPlan(context.Connection, selectStatement.SelectExpression, fromSet, selectStatement.OrderBy);
            return(selectStatement);
        }
Beispiel #2
0
        protected override DataObject OnEvaluate(IExpressionEvaluator evaluator)
        {
            // Generate the TableExpressionFromSet hierarchy for the expression,
            TableExpressionFromSet fromSet = Planner.GenerateFromSet(SelectExpression, evaluator.Context.QueryContext.Connection);

            // Form the plan
            IQueryPlanNode plan = Planner.FormQueryPlan(evaluator.Context.QueryContext.Connection, SelectExpression, fromSet, new List <ByColumn>());

            return(new DataObject(PrimitiveTypes.Query(), plan));
        }