public static InvokeResult Execute(this IRoutine routine, InvokeArgument[] args, IRequest request, IVariableResolver resolver, IGroupResolver group) { var invoke = new Invoke(routine.ObjectInfo.FullName, args); var executeContext = new InvokeContext(invoke, routine, resolver, group, request); return routine.Execute(executeContext); }
public override SqlType ReturnType(InvokeContext context) { if (method == null) method = DiscoverMethod(); return base.ReturnType(context); }
public virtual InvokeResult Execute(InvokeContext context) { var args = context.Arguments; InvokeResult invokeResult = null; try { context.Request.Context.OnEvent(new RoutineEvent(Name, args, RoutineInfo.RoutineType)); var block = context.Request.CreateBlock(); PrepareBlock(context.Arguments, block); var result = ExecuteRoutine(block); if (RoutineInfo.RoutineType == RoutineType.Function) { invokeResult = context.Result(result); } else { invokeResult = context.Result(); } var output = CollectOutput(block); if (output.Count > 0) { foreach (var pair in output) { context.SetOutput(pair.Key, pair.Value); } } return invokeResult; } catch (Exception) { throw; } finally { context.Request.Context.OnEvent(new RoutineEvent(Name, args, RoutineInfo.RoutineType, invokeResult)); } }
/// <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="query"></param> /// <returns></returns> public static DataObject Execute(this IFunction function, Invoke request, IGroupResolver group, IVariableResolver resolver, IRequest query) { var execContext = new InvokeContext(request, function, resolver, group, query); var result = function.Execute(execContext); return result.ReturnValue; }
public override SqlType ReturnType(InvokeContext context) { var returnType = FunctionInfo.ReturnType; if (returnType == null) { var methodReturnType = ExternalRef.GetMethod().ReturnType; returnType = PrimitiveTypes.FromType(methodReturnType); } return returnType; }
public static InvokeResult Execute(this IRoutine routine, SqlExpression[] args, IQuery query, IVariableResolver resolver, IGroupResolver group) { var request = new Invoke(routine.FullName, args); if (query != null && !query.UserCanExecuteFunction(request)) throw new InvalidOperationException(); var executeContext = new InvokeContext(request, routine, resolver, group, query); return routine.Execute(executeContext); }
public override InvokeResult Execute(InvokeContext context) { var args = context.EvaluatedArguments; var method = ExternalRef.GetMethod(); var methodArgs = ConvertArguments(method, context.Request, args); var result = method.Invoke(null, methodArgs); return context.Result(ConvertValue(result, ReturnType())); }
private InvokeResult(InvokeContext context, object returnValue, bool hasReturn) { Context = context; if (returnValue is ITable) { var table = (ITable) returnValue; ReturnTable = table; HasReturnTable = hasReturn; } else if (returnValue is Field) { var field = (Field) returnValue; ReturnValue = field; HasReturnValue = hasReturn; } }
public override InvokeResult Execute(InvokeContext 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) { throw; } }
public override InvokeResult Execute(InvokeContext 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.Request, 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.Request, group.GetVariableResolver(i)); result = Evaluate(result, val, context.Request, group); } } // Post method. result = PostEvaluate(result, context.Request, group); return context.Result(result); }
public override InvokeResult Execute(InvokeContext context) { using (var execContext = new ExecutionContext(context.Request, Body)) { Body.Execute(execContext); if (!execContext.HasResult) throw new InvalidOperationException("The execution of the function has no returns"); var result = execContext.Result; var returnType = ReturnType(context); if (returnType is TabularType) return context.Result(result); if (result.RowCount == 0) throw new InvalidOperationException("The execution of the function has no returns"); var retunValue = result.GetValue(0, 0); return context.Result(retunValue); } }
SqlType IFunction.ReturnType(InvokeContext context) { return Type; }
public InvokeResult Execute(InvokeContext context) { // Rewrite the function to the object initialization var sourceArgs = context.Arguments == null ? new InvokeArgument[1] : context.Arguments; var args = new InvokeArgument[sourceArgs.Length + 1]; Array.Copy(sourceArgs, 0, args, 1, sourceArgs.Length); args[0] = new InvokeArgument(SqlExpression.Constant(FunctionInfo.RoutineName.FullName)); var initFunction = context.Request.Access().ResolveObjectName(DbObjectType.Routine, ObjectName.Parse("SYSTEM.NEW_OBJECT")); if (initFunction == null) throw new InvalidOperationException("The object initialization function was not defined."); var invoke = new Invoke(initFunction, args); return invoke.Execute(context.Request, context.VariableResolver, context.GroupResolver); }
public static SqlType ReturnType(this IFunction function, Invoke request, IRequest query, IVariableResolver resolver) { var execContext = new InvokeContext(request, function, resolver, null, query); return function.ReturnType(execContext); }
public InvokeResult Execute(IRequest query, IVariableResolver resolver, IGroupResolver group) { var routine = ResolveRoutine(query); var executeContext = new InvokeContext(this, routine, resolver, group, query); return routine.Execute(executeContext); }
private static InvokeResult Simple(InvokeContext context, Func<DataObject[], DataObject> func) { var args = context.EvaluatedArguments; var funcResult = func(args); return context.Result(funcResult); }
internal InvokeResult(InvokeContext context, Field returnValue) : this(context, returnValue, true) { }
public override SqlType ReturnType(InvokeContext context) { if (returnType == null) return FunctionInfo.ReturnType; return returnType(context); }
internal InvokeResult(InvokeContext context, DataObject returnValue) : this(context, returnValue, true) { }
internal static InvokeResult Iif(InvokeContext context) { var result = DataObject.Null(); var evalContext = new EvaluateContext(context.Request, context.VariableResolver, context.GroupResolver); var condition = context.Arguments[0].EvaluateToConstant(evalContext); if (condition.Type is BooleanType) { if (condition.Equals(DataObject.BooleanTrue)) { result = context.Arguments[1].EvaluateToConstant(evalContext); } else if (condition.Equals(DataObject.BooleanFalse)) { result = context.Arguments[2].EvaluateToConstant(evalContext); } } return context.Result(result); }
internal InvokeResult(InvokeContext context, ITable table) : this(context, table, true) { }
public override InvokeResult Execute(InvokeContext context) { throw new NotImplementedException(); }
private InvokeResult(InvokeContext context, DataObject returnValue, bool hasReturn) { Context = context; ReturnValue = returnValue; HasReturnValue = hasReturn; }
internal InvokeResult(InvokeContext context) : this(context, Field.Null(), false) { }
public override InvokeResult Execute(InvokeContext context) { return functionBody(context); }
internal InvokeResult(InvokeContext context) : this(context, DataObject.Null(), false) { }