The information about the invocation of a routine, including the full name and arguments (as SqlExpression).
Esempio n. 1
0
        public override SqlExpression VisitFunctionCall(SqlFunctionCallExpression expression)
        {
            var invoke = new Invoke(expression.FunctioName, expression.Arguments);
            aggFunFound = invoke.IsAggregate(query);

            return base.VisitFunctionCall(expression);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 4
0
        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;
        }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
        public static IRoutine ResolveRoutine(this IQueryContext context, Invoke invoke)
        {
            var routine = context.ResolveSystemRoutine(invoke);
            if (routine == null)
                routine = context.ResolveUserRoutine(invoke);

            return routine;
        }
Esempio n. 7
0
        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;
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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;
        }
Esempio n. 14
0
        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);
        }
Esempio n. 16
0
        /// <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)));
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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));
        }
Esempio n. 19
0
        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);
            }
        }
Esempio n. 20
0
        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);
        }
Esempio n. 21
0
        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);
        }
Esempio n. 22
0
        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);
        }
Esempio n. 23
0
        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));
        }
Esempio n. 24
0
        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();
        }
Esempio n. 26
0
        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);
        }
Esempio n. 27
0
        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)));
        }
Esempio n. 28
0
        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;
        }
Esempio n. 29
0
        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;
 }
Esempio n. 32
0
        public static DataObject InvokeFunction(this IQuery query, Invoke invoke)
        {
            var result = invoke.Execute(query);

            return(result.ReturnValue);
        }
Esempio n. 33
0
        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;
        }
Esempio n. 37
0
 public IRoutine ResolveRoutine(Invoke invoke, IRequest context)
 {
     //TODO: support also invoke match ...
     return(GetRoutine(invoke.RoutineName));
 }
Esempio n. 38
0
 // TODO:
 public IRoutine ResolveRoutine(Invoke request, IQuery context)
 {
     return(null);
 }
Esempio n. 39
0
 public IRoutine ResolveRoutine(Invoke request, IQuery context)
 {
     // TODO: implement
     return(null);
 }
Esempio n. 40
0
        public static DataObject InvokeFunction(this IQueryContext context, Invoke invoke)
        {
            var result = invoke.Execute(context);

            return(result.ReturnValue);
        }
Esempio n. 41
0
        // TODO: public RoutineBody Body { get; private set; }

        internal abstract bool MatchesInvoke(Invoke request, IQuery query);
Esempio n. 42
0
        public static bool IsAggregateFunction(this IQueryContext context, Invoke invoke)
        {
            var function = context.ResolveFunction(invoke);

            return(function != null && function.FunctionType == FunctionType.Aggregate);
        }
Esempio n. 43
0
 IRoutine IRoutineResolver.ResolveRoutine(Invoke invoke, IRequest request)
 {
     return(ResolveFunction(invoke, request));
 }
Esempio n. 44
0
 public static FunctionInfo ResolveFunctionInfo(this IQuery query, Invoke invoke)
 {
     return(query.ResolveRoutineInfo(invoke) as FunctionInfo);
 }
Esempio n. 45
0
        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;
 }
Esempio n. 47
0
 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;
 }
Esempio n. 49
0
 public static FunctionInfo ResolveFunctionInfo(this IQueryContext context, Invoke invoke)
 {
     return(context.ResolveRoutineInfo(invoke) as FunctionInfo);
 }
Esempio n. 50
0
 public static IRoutine ResolveSystemRoutine(this IQueryContext context, Invoke invoke)
 {
     return context.SystemContext().ResolveRoutine(invoke, context);
 }
Esempio n. 51
0
 public static IRoutine ResolveRoutine(this ISession session, Invoke invoke)
 {
     return(session.GetObject(DbObjectType.Routine, invoke.RoutineName, AccessType.Read) as IRoutine);
 }
Esempio n. 52
0
 public static IFunction ResolveFunction(this IQuery query, Invoke invoke)
 {
     return(query.ResolveRoutine(invoke) as IFunction);
 }
Esempio n. 53
0
 internal abstract bool MatchesInvoke(Invoke invoke, IRequest request);
Esempio n. 54
0
 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;
        }
Esempio n. 56
0
 public static IFunction ResolveFunction(this IQueryContext context, Invoke invoke)
 {
     return(context.ResolveRoutine(invoke) as IFunction);
 }
Esempio n. 57
0
        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));
        }
Esempio n. 58
0
 public IRoutine ResolveRoutine(Invoke request, IQueryContext context)
 {
     return resolvers.Values.Select(resolver => resolver.ResolveRoutine(request, context))
         .FirstOrDefault(routine => routine != null);
 }
Esempio n. 59
0
        public static IFunction ResolveFunction(this IQueryContext context, ObjectName functionName, params SqlExpression[] args)
        {
            var invoke = new Invoke(functionName, args);

            return(context.ResolveFunction(invoke));
        }