public override SqlExpression VisitFunctionCall(SqlFunctionCallExpression expression) { var invoke = new Invoke(expression.FunctioName, expression.Arguments); aggFunFound = invoke.IsAggregate(query); return base.VisitFunctionCall(expression); }
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 static DataObject InvokeSystemFunction(this IQueryContext context, string functionName, params SqlExpression[] args) { var resolvedName = new ObjectName(SystemSchema.SchemaName, functionName); var invoke = new Invoke(resolvedName, args); return context.InvokeFunction(invoke); }
internal override bool MatchesInvoke(Invoke invoke, IQueryContext queryContext) { if (invoke == null) return false; bool ignoreCase = true; if (queryContext != null) ignoreCase = queryContext.IgnoreIdentifiersCase(); if (!RoutineName.Equals(invoke.RoutineName, ignoreCase)) return false; var inputParams = Parameters.Where(parameter => parameter.IsInput).ToList(); if (invoke.Arguments.Length != inputParams.Count) return false; for (int i = 0; i < invoke.Arguments.Length; i++) { // TODO: support variable evaluation here? or evaluate parameters before reaching here? if (!invoke.Arguments[i].IsConstant()) return false; var argType = invoke.Arguments[i].ReturnType(queryContext, null); var paramType = Parameters[i].Type; // TODO: verify if this is assignable (castable) ... if (!paramType.IsComparable(argType)) return false; } return true; }
internal override bool MatchesInvoke(Invoke invoke, IRequest request) { if (invoke == null) return false; if (!RoutineName.Equals(invoke.RoutineName)) return false; var inputParams = Parameters.Where(parameter => parameter.IsInput).ToList(); if (invoke.Arguments.Length != inputParams.Count) return false; for (int i = 0; i < invoke.Arguments.Length; i++) { if (!invoke.Arguments[i].Value.IsConstant()) return false; var argType = invoke.Arguments[i].Value.ReturnType(request, null); var paramType = Parameters[i].Type; // TODO: verify if this is assignable (castable) ... if (!paramType.IsComparable(argType)) return false; } return true; }
public static IRoutine ResolveRoutine(this IQueryContext context, Invoke invoke) { var routine = context.ResolveSystemRoutine(invoke); if (routine == null) routine = context.ResolveUserRoutine(invoke); return routine; }
public static IRoutine ResolveRoutine(this IQuery query, Invoke invoke) { var routine = query.ResolveSystemRoutine(invoke); if (routine == null) routine = query.ResolveUserRoutine(invoke); return routine; }
/// <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 static bool IsSystemFunction(this IQueryContext context, Invoke invoke) { var info = context.ResolveFunctionInfo(invoke); if (info == null) return false; return info.FunctionType != FunctionType.External && info.FunctionType != FunctionType.UserDefined; }
/// <summary> /// Checks if a function matched against the given request represents /// an aggregate function. /// </summary> /// <param name="resolver">The routine resolver.</param> /// <param name="request">The invocation request used to resolve the function.</param> /// <param name="query">The parent query context.</param> /// <returns> /// Returns <c>true</c> if a routine was resolved for the given request, /// this is a <see cref="IFunction"/> and the <see cref="FunctionType"/> is /// <see cref="FunctionType.Aggregate"/>, otherwise <c>false</c>. /// </returns> public static bool IsAggregateFunction(this IRoutineResolver resolver, Invoke request, IQuery query) { var routine = resolver.ResolveRoutine(request, query); var function = routine as IFunction; if (function == null) return false; return function.FunctionType == FunctionType.Aggregate; }
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); }
private DataObject ParseAndInvoke(string text) { var exp = SqlExpression.Parse(text); Assert.IsInstanceOf<SqlFunctionCallExpression>(exp); var functionName = ((SqlFunctionCallExpression) exp).FunctioName; var args = ((SqlFunctionCallExpression) exp).Arguments; var invoke = new Invoke(functionName, args); return QueryContext.InvokeFunction(invoke); }
internal ExecuteContext(Invoke invoke, IRoutine routine, IVariableResolver resolver, IGroupResolver group, IQueryContext queryContext) { if (invoke == null) throw new ArgumentNullException("invoke"); if (routine == null) throw new ArgumentNullException("routine"); QueryContext = queryContext; GroupResolver = group; VariableResolver = resolver; Invoke = invoke; Routine = routine; }
internal InvokeContext(Invoke invoke, IRoutine routine, IVariableResolver resolver, IGroupResolver group, IRequest request) { if (invoke == null) throw new ArgumentNullException("invoke"); if (routine == null) throw new ArgumentNullException("routine"); Request = request; GroupResolver = group; VariableResolver = resolver; Invoke = invoke; Routine = routine; }
/// <summary> /// Checks if a function matched against the given request represents /// an aggregate function. /// </summary> /// <param name="resolver">The routine resolver.</param> /// <param name="request">The invocation request used to resolve the function.</param> /// <param name="query">The parent query context.</param> /// <returns> /// Returns <c>true</c> if a routine was resolved for the given request, /// this is a <see cref="IFunction"/> and the <see cref="FunctionType"/> is /// <see cref="FunctionType.Aggregate"/>, otherwise <c>false</c>. /// </returns> public static bool IsAggregateFunction(this IRoutineResolver resolver, Invoke request, IQuery query) { var routine = resolver.ResolveRoutine(request, query); var function = routine as IFunction; if (function == null) { return(false); } return(function.FunctionType == FunctionType.Aggregate); }
/// <summary> /// Checks if the target of the invocation is an aggregate function. /// </summary> /// <param name="query">The query context used to resolve the routine.</param> /// <returns> /// Returns <c>true</c> if the target routine of the invocation is a <see cref="IFunction"/> /// and the <see cref="IFunction.FunctionType"/> is <see cref="FunctionType.Aggregate"/>, /// otherwise it returns <c>false</c>. /// </returns> public bool IsAggregate(IRequest query) { var resolvedName = query.Access().ResolveObjectName(DbObjectType.Routine, RoutineName); var invoke = new Invoke(resolvedName, Arguments); if (query.Access().IsAggregateFunction(invoke, query)) { return(true); } // Look at parameterss return(Arguments.Any(x => x.Value.HasAggregate(query))); }
internal override bool MatchesInvoke(Invoke invoke, IRequest request) { if (invoke == null) { return(false); } if (!RoutineName.Equals(invoke.RoutineName)) { return(false); } // TODO: add a better resolution to obtain the final type of the argument // and compare it to the parameter type definition bool unboundedSeen = false; for (int i = 0; i < invoke.Arguments.Length; i++) { var argType = invoke.Arguments[i].Value.ReturnType(request, null); if (i + 1 > Parameters.Length) { if (!unboundedSeen) { return(false); } // TODO: verify the type of the argument (how to evaluate?) } else { var param = Parameters[i]; unboundedSeen = param.IsUnbounded; var paramType = param.Type; if (!paramType.IsComparable(argType)) { return(false); } } } if (!unboundedSeen && invoke.Arguments.Length != Parameters.Length) { return(false); } return(true); }
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)); }
protected override void FireTrigger(TableEvent tableEvent, IBlock context) { var procedure = context.Access().GetObject(DbObjectType.Routine, ProcedureName) as IProcedure; if (procedure == null) throw new TriggerException(String.Format("The procedure '{0}' was not found.", ProcedureName)); var invoke = new Invoke(ProcedureName, Arguments); try { procedure.Execute(new InvokeContext(invoke, procedure, null, null, context)); } catch (Exception ex) { throw new TriggerException(String.Format("Error while invoking '{0}'.",invoke), ex); } }
public static IRoutine ResolveRoutine(this ISystemContext context, Invoke invoke, IQuery queryContext) { var resolvers = context.ResolveAllServices <IRoutineResolver>(); foreach (var resolver in resolvers) { var routine = resolver.ResolveRoutine(invoke, queryContext); if (routine != null) { return(routine); } } return(null); }
internal override bool MatchesInvoke(Invoke invoke, IQuery query) { if (invoke == null) { return(false); } bool ignoreCase = true; if (query != null) { ignoreCase = query.IgnoreIdentifiersCase(); } if (!RoutineName.Equals(invoke.RoutineName, ignoreCase)) { return(false); } var inputParams = Parameters.Where(parameter => parameter.IsInput).ToList(); if (invoke.Arguments.Length != inputParams.Count) { return(false); } for (int i = 0; i < invoke.Arguments.Length; i++) { // TODO: support variable evaluation here? or evaluate parameters before reaching here? if (!invoke.Arguments[i].IsConstant()) { return(false); } var argType = invoke.Arguments[i].ReturnType(query, null); var paramType = Parameters[i].Type; // TODO: verify if this is assignable (castable) ... if (!paramType.IsComparable(argType)) { return(false); } } return(true); }
public static IRoutine ResolveSystemRoutine(this IQuery query, Invoke invoke) { // return query.SystemContext().ResolveRoutine(invoke, query); var resolvers = query.Context.ResolveAllServices <IRoutineResolver>(); foreach (var resolver in resolvers) { var routine = resolver.ResolveRoutine(invoke, query); if (routine != null) { return(routine); } } return(null); }
public IFunction ResolveFunction(Invoke invoke, IQueryContext context) { var name = NormalizeName(invoke.RoutineName); if (name == null || !name.ParentName.Equals(SchemaName)) return null; var functionName = name.FullName.ToUpperInvariant(); var functions = container.ResolveMany<IFunction>(serviceKey:functionName).ToArrayOrSelf(); if (functions.Length == 0) return null; if (functions.Length == 1) return functions[0]; return functions.FirstOrDefault(x => x.RoutineInfo.MatchesInvoke(invoke, context)); }
internal InvokeContext(Invoke invoke, IRoutine routine, IVariableResolver resolver, IGroupResolver group, IRequest request) { if (invoke == null) { throw new ArgumentNullException("invoke"); } if (routine == null) { throw new ArgumentNullException("routine"); } Request = request; GroupResolver = group; VariableResolver = resolver; Invoke = invoke; Routine = routine; }
AssertResult ISecurityAssert.Assert(ISecurityContext context) { if ((Privileges & Privileges.Create) != 0) { if (ResourceType == DbObjectType.Schema) { if (!context.User.CanManageSchema()) return AssertResult.Deny(new MissingPrivilegesException(context.User.Name, ResourceName, Privileges)); } } if ((Privileges & Privileges.Execute) != 0) { var invoke = new Invoke(ResourceName, Arguments); if (context.Request.Access().IsSystemFunction(invoke, context.Request)) return AssertResult.Allow(); } if (!context.User.HasPrivileges(ResourceType, ResourceName, Privileges)) return AssertResult.Deny(new MissingPrivilegesException(context.User.Name, ResourceName, Privileges)); return AssertResult.Allow(); }
internal override bool MatchesInvoke(Invoke invoke, IRequest request) { if (invoke == null) { return(false); } if (!RoutineName.Equals(invoke.RoutineName)) { return(false); } var inputParams = Parameters.Where(parameter => parameter.IsInput).ToList(); if (invoke.Arguments.Length != inputParams.Count) { return(false); } for (int i = 0; i < invoke.Arguments.Length; i++) { if (!invoke.Arguments[i].Value.IsConstant()) { return(false); } var argType = invoke.Arguments[i].Value.ReturnType(request, null); var paramType = Parameters[i].Type; // TODO: verify if this is assignable (castable) ... if (!paramType.IsComparable(argType)) { return(false); } } return(true); }
public IFunction ResolveFunction(Invoke invoke, IRequest request) { var name = invoke.RoutineName.Name; if (name == null) { return(null); } var functionName = name.ToUpperInvariant(); var functions = container.ResolveMany <IFunction>(serviceKey: functionName).ToArrayOrSelf(); if (functions.Length == 0) { return(null); } if (functions.Length == 1) { return(functions[0]); } return(functions.FirstOrDefault(x => x.RoutineInfo.MatchesInvoke(invoke, request))); }
internal override bool MatchesInvoke(Invoke invoke, IRequest request) { if (invoke == null) return false; if (!RoutineName.Equals(invoke.RoutineName)) return false; // TODO: add a better resolution to obtain the final type of the argument // and compare it to the parameter type definition bool unboundedSeen = false; for (int i = 0; i < invoke.Arguments.Length; i++) { var argType = invoke.Arguments[i].Value.ReturnType(request, null); if (i + 1 > Parameters.Length) { if (!unboundedSeen) return false; // TODO: verify the type of the argument (how to evaluate?) } else { var param = Parameters[i]; unboundedSeen = param.IsUnbounded; var paramType = param.Type; if (!paramType.IsComparable(argType)) return false; } } if (!unboundedSeen && invoke.Arguments.Length != Parameters.Length) return false; return true; }
public IFunction ResolveFunction(Invoke invoke, IQuery query) { var name = NormalizeName(invoke.RoutineName); if (name == null || !name.ParentName.Equals(SchemaName)) { return(null); } var functionName = name.FullName.ToUpperInvariant(); var functions = container.ResolveMany <IFunction>(serviceKey: functionName).ToArrayOrSelf(); if (functions.Length == 0) { return(null); } if (functions.Length == 1) { return(functions[0]); } return(functions.FirstOrDefault(x => x.RoutineInfo.MatchesInvoke(invoke, query))); }
public static bool IsAggregateFunction(this IQueryContext context, Invoke invoke) { var function = context.ResolveFunction(invoke); return function != null && function.FunctionType == FunctionType.Aggregate; }
public static DataObject InvokeFunction(this IQueryContext context, Invoke invoke) { var result = invoke.Execute(context); return result.ReturnValue; }
public static DataObject InvokeFunction(this IQuery query, Invoke invoke) { var result = invoke.Execute(query); return(result.ReturnValue); }
public InvokeContext New(SqlExpression[] args) { var newInvoke = new Invoke(Invoke.RoutineName, args); return(new InvokeContext(newInvoke, Routine, VariableResolver, GroupResolver, Request)); }
public static IRoutine ResolveUserRoutine(this IQueryContext context, Invoke invoke) { var routine = context.Session().ResolveRoutine(invoke); if (routine != null && !context.UserCanExecute(routine.Type, invoke)) throw new InvalidOperationException(); return routine; }
public static IFunction ResolveFunction(this IQueryContext context, ObjectName functionName, params SqlExpression[] args) { var invoke = new Invoke(functionName, args); return context.ResolveFunction(invoke); }
public static RoutineInfo ResolveRoutineInfo(this IQueryContext context, Invoke invoke) { var routine = context.ResolveRoutine(invoke); if (routine == null) return null; return routine.RoutineInfo; }
public IRoutine ResolveRoutine(Invoke invoke, IRequest context) { //TODO: support also invoke match ... return(GetRoutine(invoke.RoutineName)); }
// TODO: public IRoutine ResolveRoutine(Invoke request, IQuery context) { return(null); }
public IRoutine ResolveRoutine(Invoke request, IQuery context) { // TODO: implement return(null); }
public static DataObject InvokeFunction(this IQueryContext context, Invoke invoke) { var result = invoke.Execute(context); return(result.ReturnValue); }
// TODO: public RoutineBody Body { get; private set; } internal abstract bool MatchesInvoke(Invoke request, IQuery query);
public static bool IsAggregateFunction(this IQueryContext context, Invoke invoke) { var function = context.ResolveFunction(invoke); return(function != null && function.FunctionType == FunctionType.Aggregate); }
IRoutine IRoutineResolver.ResolveRoutine(Invoke invoke, IRequest request) { return(ResolveFunction(invoke, request)); }
public static FunctionInfo ResolveFunctionInfo(this IQuery query, Invoke invoke) { return(query.ResolveRoutineInfo(invoke) as FunctionInfo); }
public override SqlExpression VisitFunctionCall(SqlFunctionCallExpression expression) { var invoke = new Invoke(expression.FunctioName, expression.Arguments); var function = invoke.ResolveRoutine(queryContext) as IFunction; if (function != null) dataType = function.ReturnType(invoke, queryContext, variableResolver); return base.VisitFunctionCall(expression); }
public static IFunction ResolveFunction(this IQueryContext context, Invoke invoke) { return context.ResolveRoutine(invoke) as IFunction; }
IRoutine IRoutineResolver.ResolveRoutine(Invoke request, IQuery query) { return(ResolveFunction(request, query)); }
public static FunctionInfo ResolveFunctionInfo(this IQueryContext context, Invoke invoke) { return context.ResolveRoutineInfo(invoke) as FunctionInfo; }
public static FunctionInfo ResolveFunctionInfo(this IQueryContext context, Invoke invoke) { return(context.ResolveRoutineInfo(invoke) as FunctionInfo); }
public static IRoutine ResolveSystemRoutine(this IQueryContext context, Invoke invoke) { return context.SystemContext().ResolveRoutine(invoke, context); }
public static IRoutine ResolveRoutine(this ISession session, Invoke invoke) { return(session.GetObject(DbObjectType.Routine, invoke.RoutineName, AccessType.Read) as IRoutine); }
public static IFunction ResolveFunction(this IQuery query, Invoke invoke) { return(query.ResolveRoutine(invoke) as IFunction); }
internal abstract bool MatchesInvoke(Invoke invoke, IRequest request);
internal abstract bool MatchesInvoke(Invoke request, IQueryContext queryContext);
public static IRoutine ResolveSystemRoutine(this IQueryContext context, Invoke invoke) { // return context.SystemContext().ResolveRoutine(invoke, context); var resolvers = context.ResolveAllServices<IRoutineResolver>(); foreach (var resolver in resolvers) { var routine = resolver.ResolveRoutine(invoke, context); if (routine != null) return routine; } return null; }
public static IFunction ResolveFunction(this IQueryContext context, Invoke invoke) { return(context.ResolveRoutine(invoke) as IFunction); }
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 IRoutine ResolveRoutine(Invoke request, IQueryContext context) { return resolvers.Values.Select(resolver => resolver.ResolveRoutine(request, context)) .FirstOrDefault(routine => routine != null); }
public static IFunction ResolveFunction(this IQueryContext context, ObjectName functionName, params SqlExpression[] args) { var invoke = new Invoke(functionName, args); return(context.ResolveFunction(invoke)); }