/// <summary> /// Executes a stored procedure or SQL batch. /// </summary> /// <param name="procOrBatch">Is a stored procedure or SQL batch.</param> public Result ExecGo(ExecArgument procOrBatch) { return(PublicInvoker.Call <Result>(Assembly.GetCallingAssembly(), (ca) => { var cpass = PassChainer.Create(_root, procOrBatch); var connectable = Reader.GetConnectable(ca, cpass, this); return Reader.LoadAll(connectable); })); }
internal static ExecChainer Create( Chainer prev, ExecArgument executable, string returnValueToVariable, ParameterArgument[] arguments) { if (executable.Exception != null) { executable.Exception.ObjectName = prev.GetRoot().Name; executable.Exception.Arguments = "executable = null"; executable.Exception.Method = Text.Method.Exec; throw executable.Exception; } QueryTalkException exception; var root = prev.GetRoot(); Variable inliner = null; if (executable.Original is System.String) { inliner = root.TryGetVariable((string)executable.Original, out exception, Variable.SearchType.Inliner); } exception = null; // stored procedure, SQL batch, mapped stored procedure if (inliner == null) { var cpass = PassChainer.Create(new InternalRoot(), executable); return(new ExecChainer((Chainer)prev, cpass, returnValueToVariable)); } // inliner: stored procedure, procedure, SQL else { if (inliner.DT == DT.InProcedure) { return(new ExecChainer(prev, inliner, returnValueToVariable, arguments)); } else if (inliner.DT == DT.InStoredProcedure) { return(new ExecChainer(prev, inliner, returnValueToVariable, arguments)); } else if (inliner.DT == DT.InSql) { return(new ExecChainer(prev, inliner, returnValueToVariable, arguments)); } else { exception = inliner.DT.InvalidInlinerException(typeof(ExecChainer).ToString(), inliner.Name, _inliners); exception.ObjectName = root.Name; exception.Method = Text.Method.Exec; throw exception; } } }
/// <summary> /// Executes a stored procedure or SQL batch asynchronously. /// </summary> /// <param name="procOrBatch">Is a stored procedure or SQL batch.</param> /// <param name="onCompleted">A delegate method that is called when the asynchronous operation completes.</param> /// <returns>The object of the asynchronous operation.</returns> public Async ExecGoAsync(ExecArgument procOrBatch, Action <Result> onCompleted = null) { return(PublicInvoker.Call <Async>(Assembly.GetCallingAssembly(), (ca) => { var cpass = PassChainer.Create(_root, procOrBatch); var connectable = Reader.GetConnectable(ca, cpass, this); connectable.OnAsyncCompleted = onCompleted; return Reader.LoadAllAsync(connectable); })); }
/// <summary> /// Executes a stored procedure or SQL batch asynchronously. /// </summary> /// <typeparam name="T">The type of the result set that is returned by the execution.</typeparam> /// <param name="procOrBatch">Is a stored procedure or SQL batch.</param> /// <param name="onCompleted">A delegate method that is called when the asynchronous operation completes.</param> /// <returns>The object of the asynchronous operation.</returns> public Async <Result <T> > ExecGoAsync <T>(ExecArgument procOrBatch, Action <Result <T> > onCompleted = null) { return(PublicInvoker.Call <Async <Result <T> > >(Assembly.GetCallingAssembly(), (ca) => { var cpass = PassChainer.Create(_root, procOrBatch); var connectable = Reader.GetConnectable(ca, cpass, this); connectable.OnAsyncCompleted = onCompleted; if (typeof(T) == typeof(DataTable)) { return Reader.LoadDataTableAsync <T>(connectable); } else { return Reader.LoadTableAsync <T>(connectable, null); } })); }
/// <summary> /// Executes a stored procedure or SQL batch. /// </summary> /// <typeparam name="T">The type of the result set that is returned by the execution.</typeparam> /// <param name="procOrBatch">Is a stored procedure or SQL batch.</param> public Result <T> ExecGo <T>(ExecArgument procOrBatch) { return(PublicInvoker.Call <Result <T> >(Assembly.GetCallingAssembly(), (ca) => { var cpass = PassChainer.Create(_root, procOrBatch); var connectable = Reader.GetConnectable(ca, cpass, this); Result <T> result; if (typeof(T) == typeof(DataTable)) { result = Reader.LoadDataTable <T>(connectable); } else { result = Reader.LoadTable <T>(connectable, null); } return result; })); }
// 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)); } }; }