public override ExecuteResult Execute(ExecuteContext context)
        {
            if (Body == null)
                throw new InvalidOperationException();

            throw new NotImplementedException();
        }
        protected override void Dispose(bool disposing)
        {
            parentContext = null;
            executeContext = null;

            base.Dispose(disposing);
        }
Beispiel #3
0
        public override DataType ReturnType(ExecuteContext context)
        {
            if (method == null)
                method = DiscoverMethod();

            return base.ReturnType(context);
        }
        public FunctionQueryContext(IQueryContext parentContext, ExecuteContext executeContext)
        {
            if (parentContext == null)
                throw new ArgumentNullException("parentContext");
            if (executeContext == null)
                throw new ArgumentNullException("executeContext");

            this.parentContext = parentContext;
            this.executeContext = executeContext;
        }
Beispiel #5
0
        /// <summary>
        /// Executes the function given the cintext provided.
        /// </summary>
        /// <param name="function">The function to execute.</param>
        /// <param name="request">The invocation information that was used to resolve 
        /// the function.</param>
        /// <param name="group"></param>
        /// <param name="resolver"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static DataObject Execute(this IFunction function,
			Invoke request,
			IGroupResolver group,
			IVariableResolver resolver,
			IQueryContext context)
        {
            var execContext = new ExecuteContext(request, function, resolver, group, context);
            var result = function.Execute(execContext);
            return result.ReturnValue;
        }
Beispiel #6
0
        public static ExecuteResult Execute(this IRoutine routine, SqlExpression[] args, IQueryContext context, IVariableResolver resolver, IGroupResolver group)
        {
            var request = new Invoke(routine.FullName, args);

            if (context != null &&
                !context.UserCanExecuteFunction(request))
                throw new InvalidOperationException();

            var executeContext = new ExecuteContext(request, routine, resolver, group, context);
            return routine.Execute(executeContext);
        }
Beispiel #7
0
        public override ExecuteResult Execute(ExecuteContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            var group = context.GroupResolver;

            if (group == null)
                throw new Exception(String.Format("'{0}' can only be used as an aggregate function.", FunctionName));

            DataObject result = null;
            // All aggregates functions return 'null' if group size is 0
            int size = group.Count;
            if (size == 0) {
                // Return a NULL of the return type
                return context.Result(DataObject.Null(ReturnType(context)));
            }

            DataObject val;
            ObjectName v = context.Arguments[0].AsReferenceName();
            // If the aggregate parameter is a simple variable, then use optimal
            // routine,
            if (v != null) {
                for (int i = 0; i < size; ++i) {
                    val = group.Resolve(v, i);
                    result = Evaluate(result, val, context.QueryContext, group);
                }
            } else {
                // Otherwise we must resolve the expression for each entry in group,
                // This allows for expressions such as 'sum(quantity * price)' to
                // work for a group.
                var exp = context.Arguments[0];
                for (int i = 0; i < size; ++i) {
                    val = exp.EvaluateToConstant(context.QueryContext, group.GetVariableResolver(i));
                    result = Evaluate(result, val, context.QueryContext, group);
                }
            }

            // Post method.
            result = PostEvaluate(result, context.QueryContext, group);

            return context.Result(result);
        }
Beispiel #8
0
        public override ExecuteResult Execute(ExecuteContext context)
        {
            if (method == null)
                method = DiscoverMethod();

            if (method == null)
                throw new InvalidOperationException();

            var args = context.EvaluatedArguments;

            try {
                var methodArgs = ConvertArguments(method, args);
                var result = method.Invoke(null, methodArgs);

                return  context.Result(ConvertValue(result, ReturnType()));
            } catch (Exception ex) {
                throw;
            }
        }
Beispiel #9
0
 internal ExecuteResult(ExecuteContext context, DataObject returnValue)
     : this(context, returnValue, true)
 {
 }
Beispiel #10
0
 /// <summary>
 /// Executes the function and provides a result.
 /// </summary>
 /// <param name="context">The context of the execution.</param>
 /// <returns>
 /// Returns a <see cref="ExecuteResult"/> instance that encapsulates
 /// the returned value of the function.
 /// </returns>
 /// <seealso cref="ExecuteResult.ReturnValue"/>
 public abstract ExecuteResult Execute(ExecuteContext context);
Beispiel #11
0
 public override ExecuteResult Execute(ExecuteContext context)
 {
     throw new NotImplementedException();
 }
            public static ExecuteResult Execute(ExecuteContext context)
            {
                if (context.GroupResolver == null)
                    throw new Exception("'count' can only be used as an aggregate function.");

                int size = context.GroupResolver.Count;
                DataObject result;
                // if, count(*)
                if (size == 0 || context.Invoke.IsGlobArgument) {
                    result = DataObject.Integer(size);
                } else {
                    // Otherwise we need to count the number of non-null entries in the
                    // columns list(s).

                    int totalCount = size;

                    var exp = context.Arguments[0];
                    for (int i = 0; i < size; ++i) {
                        var val = exp.EvaluateToConstant(context.QueryContext, context.GroupResolver.GetVariableResolver(i));
                        if (val.IsNull) {
                            --totalCount;
                        }
                    }

                    result = DataObject.Integer(totalCount);
                }

                return context.Result(result);
            }
 private ExecuteResult Simple(ExecuteContext context, Func<DataObject[], DataObject> func)
 {
     var evaluated = context.EvaluatedArguments;
     var value = func(evaluated);
     return context.Result(value);
 }
 private ExecuteResult Binary(ExecuteContext context, Func<DataObject, DataObject, DataObject> func)
 {
     var evaluated = context.EvaluatedArguments;
     var value = func(evaluated[0], evaluated[1]);
     return context.Result(value);
 }
Beispiel #15
0
 public static DataType ReturnType(this IFunction function, Invoke request, IQueryContext context, IVariableResolver resolver)
 {
     var execContext = new ExecuteContext(request, function, resolver, null, context);
     return function.ReturnType(execContext);
 }
Beispiel #16
0
 private ExecuteResult(ExecuteContext context, DataObject returnValue, bool hasReturn)
 {
     Context = context;
     ReturnValue = returnValue;
     HasReturnValue = hasReturn;
 }
Beispiel #17
0
 public ExecuteResult Execute(IQueryContext context, IVariableResolver resolver, IGroupResolver group)
 {
     var routine = ResolveRoutine(context);
     var executeContext = new ExecuteContext(this, routine, resolver, group, context);
     return routine.Execute(executeContext);
 }
            public static ExecuteResult Execute(ExecuteContext context)
            {
                var value = context.EvaluatedArguments[0];
                var typeArg = context.EvaluatedArguments[1];
                var typeString = typeArg.AsVarChar().Value.ToString();
                var type = SqlType.Parse(context.QueryContext, typeString);

                return context.Result(SystemFunctions.Cast(value, type));
            }
 public static SqlType ReturnType(ExecuteContext context)
 {
     var typeArg = context.EvaluatedArguments[1];
     var typeString = typeArg.AsVarChar().Value.ToString();
     return SqlType.Parse(context.QueryContext, typeString);
 }
 public static ExecuteResult Execute(ExecuteContext context)
 {
     throw new NotImplementedException();
 }
 private static ExecuteResult Simple(ExecuteContext context, Func<DataObject[], DataObject> func)
 {
     var args = context.EvaluatedArguments;
     var funcResult = func(args);
     return context.Result(funcResult);
 }
Beispiel #22
0
 public override ExecuteResult Execute(ExecuteContext context)
 {
     return functionBody(context);
 }
Beispiel #23
0
 /// <summary>
 /// Resolves the function return type against the given context.
 /// </summary>
 /// <param name="context">The execution context used to resolve
 /// the function return type.</param>
 /// <returns>
 /// Returns an instance of <see cref="SqlType"/> that defines
 /// the type of the returned value resolved against the given
 /// execution context..
 /// </returns>
 public virtual SqlType ReturnType(ExecuteContext context)
 {
     return FunctionInfo.ReturnType;
 }
Beispiel #24
0
            public override SqlType ReturnType(ExecuteContext context)
            {
                if (returnType == null)
                    return FunctionInfo.ReturnType;

                return returnType(context);
            }
Beispiel #25
0
 internal ExecuteResult Execute(ExecuteContext context)
 {
     throw new NotImplementedException();
 }
Beispiel #26
0
 internal ExecuteResult(ExecuteContext context)
     : this(context, DataObject.Null(), false)
 {
 }