Наследование: ISerializable, IPreparable, ISqlFormattable
 public ResourceAccessSecurityAssert(ObjectName resourceName, DbObjectType resourceType, Privileges privileges)
 {
     ResourceName = resourceName;
     ResourceType = resourceType;
     Privileges = privileges;
     Arguments = new InvokeArgument[0];
 }
Пример #2
0
        public void WithNamedArgument()
        {
            var procName = ObjectName.Parse("APP.proc1");
            var arg = new InvokeArgument("a", SqlExpression.Constant("Hello!"));

            AdminQuery.Call(procName, arg);
        }
Пример #3
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);
        }
Пример #4
0
        public void WithNamedArguments()
        {
            var procName = ObjectName.Parse("APP.proc2");
            var arg1 = new InvokeArgument("a", SqlExpression.Constant("Hello"));
            var arg2 = new InvokeArgument("b", SqlExpression.Constant("World!"));

            AdminQuery.Call(procName, arg1, arg2);
        }
Пример #5
0
        public ProcedureTriggerInfo(ObjectName triggerName, ObjectName tableName, TriggerEventTime eventTime, TriggerEventType eventType, ObjectName procedureName, InvokeArgument[] args)
            : base(triggerName, TriggerType.External, tableName, eventTime, eventType)
        {
            if (procedureName == null)
                throw new ArgumentNullException("procedureName");

            ProcedureName = procedureName;
            Arguments = args;
        }
Пример #6
0
        /// <summary>
        /// Constructs a new <see cref="Invoke"/> with the given
        /// name of the routine and the arguments.
        /// </summary>
        /// <param name="routineName">The fully qualified name of the routine
        /// to be invoked.</param>
        /// <param name="arguments">The arguments to pass to the routine.</param>
        public Invoke(ObjectName routineName, InvokeArgument[] arguments)
        {
            if (routineName == null)
                throw new ArgumentNullException("routineName");

            VerifyNamesIn(arguments);

            RoutineName = routineName;
            Arguments = arguments;
        }
Пример #7
0
        public RoutineEvent(RoutineEventType eventType, ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType, InvokeResult result)
        {
            if (routineName == null)
                throw new ArgumentNullException("routineName");

            EventType = eventType;
            RoutineName = routineName;
            Arguments = arguments;
            RoutineType = routineType;
            Result = result;
        }
Пример #8
0
        public static InvokeResult Execute(this IRoutine routine, Field[] args)
        {
            var invokeArgs = new InvokeArgument[0];
            if (args != null && args.Length > 0) {
                invokeArgs = new InvokeArgument[args.Length];

                for (int i = 0; i < args.Length; i++) {
                    invokeArgs[i] = new InvokeArgument(SqlExpression.Constant(args[i]));
                }
            }

            return routine.Execute(invokeArgs);
        }
Пример #9
0
        public void CallExternalWithArguments()
        {
            var procName = ObjectName.Parse("APP.extProc");
            var arg1 = new InvokeArgument("a", SqlExpression.Constant("Hello"));
            var arg2 = new InvokeArgument("b", SqlExpression.Constant("World!"));

            var result = AdminQuery.Call(procName, arg1, arg2);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);

            Assert.IsNotNullOrEmpty(ExternProcedureResult);
            Assert.AreEqual("Hello World!", ExternProcedureResult);
        }
        public static InvokeResult Execute(this IRoutine routine, Field[] args)
        {
            var invokeArgs = new InvokeArgument[0];

            if (args != null && args.Length > 0)
            {
                invokeArgs = new InvokeArgument[args.Length];

                for (int i = 0; i < args.Length; i++)
                {
                    invokeArgs[i] = new InvokeArgument(SqlExpression.Constant(args[i]));
                }
            }

            return(routine.Execute(invokeArgs));
        }
        public static void ProcedureTrigger_WithArguments()
        {
            var args = new InvokeArgument[] {
                new InvokeArgument("a", SqlExpression.Constant(3))
            };

            var statement = new CreateProcedureTriggerStatement(ObjectName.Parse("APP.trig1"), new ObjectName("tab1"),
                ObjectName.Parse("APP.proc1"), args, TriggerEventTime.After, TriggerEventType.Delete) {
                    ReplaceIfExists = true,
                    Status = TriggerStatus.Enabled
                };

            var expected = "CREATE OR REPLACE TRIGGER APP.trig1 AFTER DELETE ON tab1 FOR EACH ROW ENABLE CALL APP.proc1(a => 3)";

            Assert.AreEqual(expected, statement.ToString());
        }
        public CreateProcedureTriggerStatement(ObjectName triggerName, ObjectName tableName, ObjectName procedureName, InvokeArgument[] args, TriggerEventTime eventTime, TriggerEventType eventType)
        {
            if (triggerName == null)
                throw new ArgumentNullException("triggerName");
            if (tableName == null)
                throw new ArgumentNullException("tableName");
            if (procedureName == null)
                throw new ArgumentNullException("procedureName");

            TriggerName = triggerName;
            TableName = tableName;
            ProcedureName = procedureName;
            ProcedureArguments = args;
            EventTime = eventTime;
            EventType = eventType;
        }
Пример #13
0
        public void WithOutputArgument()
        {
            var procName = ObjectName.Parse("APP.proc3");
            var arg = new InvokeArgument("a", SqlExpression.Constant("Hello"));

            var result = AdminQuery.Call(procName, arg);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);

            Field value;
            Assert.IsTrue(result.TryGetValue("b", out value));
            Assert.IsFalse(Field.IsNullField(value));

            Assert.AreEqual("Hello", ((SqlString) value.Value).ToString());
        }
Пример #14
0
            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);
            }
Пример #15
0
        public void CallWithArgs()
        {
            var name = ObjectName.Parse("APP.proc1");
            var args = new InvokeArgument[] {
                new InvokeArgument(SqlExpression.Constant(32)),
                new InvokeArgument(SqlExpression.Reference(new ObjectName("a")))
            };

            var statement = new CallStatement(name, args);

            SerializeAndAssert(statement, (serialized, deserialized) => {
                Assert.IsNotNull(deserialized);
                Assert.IsNotNull(deserialized.ProcedureName);
                Assert.IsNotNull(deserialized.Arguments);
                Assert.IsNotEmpty(deserialized.Arguments);

                Assert.AreEqual("APP", deserialized.ProcedureName.ParentName);
                Assert.AreEqual("proc1", deserialized.ProcedureName.Name);
            });
        }
Пример #16
0
        public void CreateProcedureTrigger()
        {
            var procName = ObjectName.Parse("APP.proc1");
            var args = new InvokeArgument[] {
                new InvokeArgument(SqlExpression.Constant(2)),
            };
            var statement = new CreateProcedureTriggerStatement(ObjectName.Parse("APP.trig1"), new ObjectName("tab1"), procName, args,
                TriggerEventTime.Before, TriggerEventType.Insert | TriggerEventType.Update);

            SerializeAndAssert(statement, (serialized, deserialized) => {
                Assert.IsNotNull(deserialized);
                Assert.IsNotNull(deserialized.TriggerName);
                Assert.IsNotNull(deserialized.TableName);
                Assert.IsNotNull(deserialized.ProcedureArguments);
                Assert.AreEqual("APP.trig1", deserialized.TriggerName.FullName);
                Assert.AreEqual("tab1", deserialized.TableName.FullName);
                Assert.AreEqual(TriggerEventTime.Before, deserialized.EventTime);
            });
        }
Пример #17
0
 public TriggerArgument(InvokeArgument[] args)
 {
     Arguments = args;
 }
Пример #18
0
        private void PrepareBlock(InvokeArgument[] args, IBlock block)
        {
            if ((args == null || args.Length == 0) &&
                Parameters.Length == 0)
                return;

            if (args == null || args.Length == 0) {
                if (!Parameters.Any(x => x.IsInput))
                    throw new ArgumentException("Invalid number of parameters in the routine invoke.");

                return;
            }

            if (args.Length != Parameters.Count(x => x.IsInput))
                throw new ArgumentException("Invalid number of parameters in the routine invoke.");

            var passedParameters = new List<string>();

            if (args.Any(x => x.IsNamed)) {
                var parameters = Parameters.ToDictionary(x => x.Name, y => y);
                foreach (var argument in args) {
                    RoutineParameter parameter;
                    if (!parameters.TryGetValue(argument.Name, out parameter))
                        throw new ArgumentException(
                            String.Format("Invoking routine '{0}' with the named argument '{1}' that is not a parameter of the routine.",
                                Name, argument.Name));

                    if (!parameter.IsInput)
                        throw new ArgumentException(String.Format("Cannot pass any value for parameter '{0}' of routine '{1}'.",
                            parameter.Name, Name));

                    if (parameter.IsOutput) {
                        block.DeclareVariable(parameter.Name, parameter.Type, argument.Value);
                    } else {
                        block.DeclareConstantVariable(parameter.Name, parameter.Type, argument.Value);
                    }

                    passedParameters.Add(parameter.Name);
                }
            } else {
                var parameters = Parameters.Where(x => x.IsInput).OrderBy(x => x.Offset).ToArray();
                for (int i = 0; i < parameters.Length; i++) {
                    var parameter = parameters[i];
                    var argument = args[i];

                    if (parameter.IsOutput) {
                        block.DeclareVariable(parameter.Name, parameter.Type, argument.Value);
                    } else {
                        block.DeclareConstantVariable(parameter.Name, parameter.Type, argument.Value);
                    }

                    passedParameters.Add(parameter.Name);
                }
            }

            var output = Parameters.Where(x => x.IsOutput && !passedParameters.Contains(x.Name));
            foreach (var parameter in output) {
                block.DeclareVariable(parameter.Name, parameter.Type);
            }
        }
Пример #19
0
 public static SqlFunctionCallExpression FunctionCall(string functionName, InvokeArgument[] args)
 {
     return FunctionCall(ObjectName.Parse(functionName), args);
 }
        protected override SqlStatement PrepareExpressions(IExpressionPreparer preparer)
        {
            var args = new InvokeArgument[ProcedureArguments == null ? 0 : ProcedureArguments.Length];
            if (ProcedureArguments != null) {
                for (int i = 0; i < args.Length; i++) {
                    args[i] = (InvokeArgument) (ProcedureArguments[i] as IPreparable).Prepare(preparer);
                }
            }

            return new CreateProcedureTriggerStatement(TriggerName, TableName, ProcedureName, args, EventTime, EventType) {
                Status = Status,
                ReplaceIfExists = ReplaceIfExists
            };
        }
Пример #21
0
 internal SqlFunctionCallExpression(ObjectName functioName, InvokeArgument[] arguments)
 {
     Arguments = arguments;
     FunctioName = functioName;
 }
Пример #22
0
 public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments)
     : this(RoutineEventType.BeforeResolve, routineName, arguments, new RoutineType(), null)
 {
 }
Пример #23
0
 public RoutineEvent(RoutineEventType eventType, ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType)
     : this(eventType, routineName, arguments, routineType, null)
 {
 }
Пример #24
0
 public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType)
     : this(RoutineEventType.BeforeExecute, routineName, arguments, routineType, null)
 {
 }
Пример #25
0
 public RoutineEvent(ObjectName routineName, InvokeArgument[] arguments, RoutineType routineType, InvokeResult result)
     : this(RoutineEventType.AfterExecute, routineName, arguments, routineType, result)
 {
 }
Пример #26
0
        protected override void GetData(SerializationInfo info)
        {
            info.AddValue("Procedure", ProcedureName);

            var args = new InvokeArgument[0];
            if (Arguments != null)
                args = Arguments.ToArray();

            info.AddValue("Arguments", args);
        }
Пример #27
0
 public virtual InvokeArgument VisitInvokeArgument(InvokeArgument argument)
 {
     var value = Visit(argument.Value);
     return new InvokeArgument(argument.Name, value);
 }
Пример #28
0
        public virtual InvokeArgument[] VisitInvokeArgumentList(InvokeArgument[] arguments)
        {
            if (arguments == null || arguments.Length == 0)
                return arguments;

            var newArgs = new InvokeArgument[arguments.Length];
            for (int i = 0; i < arguments.Length; i++) {
                newArgs[i] = VisitInvokeArgument(arguments[i]);
            }

            return newArgs;
        }
Пример #29
0
        private static void VerifyNamesIn(InvokeArgument[] arguments)
        {
            if (arguments == null || arguments.Length == 0)
                return;

            bool hasName = false;
            foreach (var argument in arguments) {
                if (argument.IsNamed) {
                    hasName = true;
                } else if (hasName) {
                    throw new ArgumentException("At least one of the argument is named and another is unnamed.");
                }
            }
        }
Пример #30
0
 public CallStatement(ObjectName procedureName, InvokeArgument[] arguments)
 {
     ProcedureName = procedureName;
     Arguments = arguments;
 }
Пример #31
0
 public static SqlFunctionCallExpression FunctionCall(ObjectName functionName, InvokeArgument[] args)
 {
     return new SqlFunctionCallExpression(functionName, args);
 }