Пример #1
0
        protected override async Task <bool> CanLoopAsync(StatementContext context)
        {
            var variable = context.ResolveVariable(IndexName);

            var valueExp = await variable.Evaluate(context);

            var value = await valueExp.ReduceToConstantAsync(context);

            if (Reverse)
            {
                var lowerBound = (SqlObject)context.Metadata["lowerBound"];
                if (value.LessOrEqualThan(lowerBound).IsTrue)
                {
                    return(false);
                }
            }
            else
            {
                var upperBound = (SqlObject)context.Metadata["upperBound"];
                if (value.GreaterThanOrEqual(upperBound).IsTrue)
                {
                    return(false);
                }
            }

            return(await base.CanLoopAsync(context));
        }
Пример #2
0
        protected override async Task AfterLoopAsync(StatementContext context)
        {
            var variable = context.ResolveVariable(IndexName);

            var value = await variable.Evaluate(context);

            if (Reverse)
            {
                variable.SetValue(SqlExpression.Subtract(value, SqlExpression.Constant(SqlObject.BigInt(1))), context);
            }
            else
            {
                variable.SetValue(SqlExpression.Add(value, SqlExpression.Constant(SqlObject.BigInt(1))), context);
            }

            // TODO: resolve the variable from the context and increment
            await base.AfterLoopAsync(context);
        }