Пример #1
0
        public static void MatchInvoke()
        {
            var name = ObjectName.Parse("a.proc");
            var info = new SqlMethodInfo(name);

            info.Parameters.Add(new SqlParameterInfo("a", PrimitiveTypes.Integer()));
            var procedure = new SqlProcedureDelegate(info, methodContext => Task.CompletedTask);

            var invoke = new Invoke(name, new[] { new InvokeArgument(SqlObject.BigInt(11)) });

            Assert.True(procedure.Matches(null, invoke));
        }
Пример #2
0
        public static void GetString()
        {
            var name = ObjectName.Parse("a.proc");
            var info = new SqlMethodInfo(name);

            info.Parameters.Add(new SqlParameterInfo("a", PrimitiveTypes.Integer()));
            var function = new SqlProcedureDelegate(info, ctx => {
                var a = ctx.Value("a");
                var b = a.Multiply(SqlObject.BigInt(2));

                Console.Out.WriteLine("a * 2 = {0}", b);
            });

            var sql = $"PROCEDURE a.proc(a INTEGER)";

            Assert.Equal(sql, function.ToString());
        }
Пример #3
0
        public async Task ExecuteWithNamedArgs()
        {
            var name = ObjectName.Parse("a.func");
            var info = new SqlMethodInfo(name);

            info.Parameters.Add(new SqlParameterInfo("a", PrimitiveTypes.Integer()));
            var procedure = new SqlProcedureDelegate(info, ctx => {
                var a = ctx.Value("a");
                var b = a.Multiply(SqlObject.BigInt(2));
                Console.Out.WriteLine("a * 2 = {0}", b);
            });

            Assert.Equal(name, info.MethodName);

            var result = await procedure.ExecuteAsync(context, new InvokeArgument("a", SqlObject.Integer(22)));

            Assert.NotNull(result);
            Assert.False(result.HasReturnedValue);
        }
Пример #4
0
        public async void ExecuteWithOutputArgs()
        {
            var name = ObjectName.Parse("a.proc");
            var info = new SqlMethodInfo(name);

            info.Parameters.Add(new SqlParameterInfo("a", PrimitiveTypes.Integer()));
            info.Parameters.Add(new SqlParameterInfo("b", PrimitiveTypes.Integer(), SqlParameterDirection.Out));

            var procedure = new SqlProcedureDelegate(info, ctx => {
                var a = ctx.Value("a");
                var b = a.Multiply(SqlObject.Integer(2));

                ctx.SetOutput("b", SqlExpression.Constant(b));
            });

            Assert.Equal(name, info.MethodName);

            var result = await procedure.ExecuteAsync(context, new InvokeArgument("a", SqlObject.Integer(22)));

            Assert.NotNull(result);
            Assert.False(result.HasReturnedValue);
            Assert.NotEmpty(result.Output);
        }