Ejemplo n.º 1
0
        // inliner: procedure, snippet, stored procedure
        private ExecChainer(
            Chainer prev,
            Variable inliner,
            string returnValueToVariable,
            params ParameterArgument[] arguments) : base(prev)
        {
            Build = (buildContext, buildArgs) =>
            {
                ParameterArgument inlinerArgument = buildArgs.Executable.GetInlinerArgument(inliner.Name);
                if (inlinerArgument.Value == null)
                {
                    buildContext.TryTakeException(new QueryTalkException(this,
                                                                         QueryTalkExceptionType.InlinerArgumentNull,
                                                                         String.Format("{0} = null", inliner.Name)));
                    return(null);
                }

                if (inliner.DT == DT.InProcedure)
                {
                    if (inlinerArgument.DT != DT.InProcedure)
                    {
                        buildContext.TryTakeException(inliner.DT.InvalidInlinerException(GetType().Name,
                                                                                         inliner.Name, _procInliners));
                        return(null);
                    }

                    PassChainer cpass;
                    if (inlinerArgument.ArgType == typeof(PassChainer))
                    {
                        cpass = (PassChainer)inlinerArgument.Original;
                    }
                    // inliner variable
                    else
                    {
                        var proc = (Procedure)inlinerArgument.Original;
                        cpass = new PassChainer(proc, arguments);
                    }

                    BodyMethod(cpass, returnValueToVariable);

                    return(BuildExecProc(buildContext, buildArgs));
                }
                else if (inliner.DT == DT.InStoredProcedure)
                {
                    if (inlinerArgument.DT != DT.InStoredProcedure)
                    {
                        buildContext.TryTakeException(inliner.DT.InvalidInlinerException(GetType().Name,
                                                                                         inliner.Name, _sprocInliners));
                        return(null);
                    }

                    PassChainer cpass;
                    if (inlinerArgument.ArgType == typeof(PassChainer))
                    {
                        cpass = (PassChainer)inlinerArgument.Original;
                    }
                    else if (inlinerArgument.ArgType == typeof(ExecArgument))
                    {
                        cpass = PassChainer.Create(new InternalRoot(), (ExecArgument)inlinerArgument.Original);
                    }
                    // inliner variable
                    else
                    {
                        var execArgument = ((string)inlinerArgument.Original).Pass(arguments);
                        cpass = PassChainer.Create(new InternalRoot(), execArgument);
                    }

                    BodyMethod(cpass, returnValueToVariable);

                    return(BuildExecProc(buildContext, buildArgs));
                }
                else
                {
                    if (inlinerArgument.DT != DT.InSql)
                    {
                        buildContext.TryTakeException(inliner.DT.InvalidInlinerException(GetType().Name,
                                                                                         inliner.Name, _sqlInliners));
                        return(null);
                    }

                    PassChainer cpass;
                    if (inlinerArgument.ArgType == typeof(ExecArgument))
                    {
                        cpass = PassChainer.Create(new InternalRoot(), (ExecArgument)inlinerArgument.Original);
                    }
                    // inliner variable
                    else
                    {
                        var execArgument = ((string)inlinerArgument.Original).Pass(arguments);
                        cpass = PassChainer.Create(new InternalRoot(), execArgument);
                    }

                    BodyMethod(cpass, null);

                    return(BuildExecProc(buildContext, buildArgs));
                }
            };
        }