protected override void ExecuteStatement(ExecutionContext context)
{
if (!context.Request.Context.CursorExists(CursorName))
throw new StatementException(String.Format("The cursor '{0}' was not found in the current context.", CursorName));
var cursor = context.Request.Context.FindCursor(CursorName);
if (cursor == null)
throw new StatementException(String.Format("The cursor '{0}' was not found in the current context.", CursorName));
if (cursor.Status == CursorStatus.Closed)
throw new StatementException(String.Format("The cursor '{0}' was already closed.", CursorName));
int offset = -1;
if (OffsetExpression != null)
offset = OffsetExpression.EvaluateToConstant(context.Request, null);
var fetchContext = new FetchContext(context.Request, Direction, ReferenceExpression);
if (Direction == FetchDirection.Absolute ||
Direction == FetchDirection.Relative)
fetchContext.Offset = offset;
cursor.FetchInto(fetchContext);
}