// ctor for SQL batch internal PassChainer(IStoredProc prev, ParameterArgument[] arguments, List <string> batchParameters) : this((Chainer)prev) { var root = GetRoot(); // check arguments-params count int argumentsCount = arguments == null ? 0 : arguments.Count(); int parametersCount = batchParameters.Count; if (argumentsCount != parametersCount) { ThrowArgumentCountMismatch(parametersCount, argumentsCount); } if (arguments == null) { arguments = new ParameterArgument[] { null }; } int i = 0; Array.ForEach(arguments, argument => { if (argument == null) { argument = Designer.Null; } TryThrow(argument.Exception); // infer data type from value var param = Variable.InferParam(root, argument, out chainException, batchParameters[i++]); TryThrow(); root.TryAddParamOrThrow(param, true); }); Executable = new Executable((Compilable)prev, arguments); }
internal PassChainer(Chainer prev, ParameterArgument[] arguments) : this(prev) { Compilable compilable = (Compilable)prev; var root = GetRoot(); if (arguments == null) { arguments = new ParameterArgument[] { Designer.Null }; } // check arguments-params count match int argumentsCount = arguments.Count(); int explicitParamsCount = root.ExplicitParams.Count; if (!root.ParamCountCheck(argumentsCount)) { ThrowArgumentCountMismatch(explicitParamsCount, argumentsCount); } // check each argument int i = 0; Array.ForEach(arguments, argument => { if (argument != null && argument.Exception != null) { if (argument.Exception.Arguments == null && i < root.ExplicitParams.Count) { argument.Exception.Arguments = String.Format("param = {0}", root.ExplicitParams[i].Name); } TryThrow(argument.Exception); } ++i; }); Executable = new Executable(compilable, arguments); }
private string BuildConcatParams() { StringBuilder declaration = Text.GenerateSql(100); StringBuilder assignment = Text.GenerateSql(100); bool first = true; ConcatRoot.AllParams .Where(param => !param.DT.IsVTB()).ToList() // exclude table variables, temp tables and bulk tables .ForEach(param => { assignment.NewLine(Text.Comma); if (!first) { declaration.NewLine(Text.Comma); } string declare; string assign; // parameterized value: if (param.ParameterizedValue != null) { declare = Executable.GetParamDeclaration(param.ParameterizedValue, true, false); var value = param.ParameterizedValue; if (value.DataType != null) { assign = Mapping.Build(value.Value, value.DataType); } else { assign = Mapping.BuildUnchecked(value.Value); } } // SQL variable: else { declare = param.BuildDeclaration(); assign = param.Name; // assign the same outer variable } declaration .Append(param.Name) .Append(Text._As_) .Append(declare); assignment.Append(param.Name) .Append(Text.Equal) .Append(assign); first = false; }); return(Text.GenerateSql(200) .NewLine(Text.Free.CommaNSingleQuote) .Append(declaration) .Append(Text.SingleQuote) .Append(assignment) .ToString()); }
// ctor for mapped stored procedure internal PassChainer(DbProcedure dbProcedure) : this(dbProcedure.Mapper) { Executable = new Executable((Compilable)dbProcedure.Mapper, dbProcedure.Arguments); }
// build the most outer SQL wrapper internal string BuildOutputWrapper(string execSql) { var root = Executable.Compilable.GetRoot(); var outputArguments = ParameterArgument.GetOutputArguments(Executable.Arguments); var sql = Text.GenerateSql(1000).Append(Text.Free.QueryTalkCode); // after: drop temp tables var sqlAfter = Text.GenerateSql(100); sqlAfter.Append(DropTempTables()); if (root.IsEmbeddedTryCatch) { sqlAfter .NewLine(Text.EndTry) .NewLine(Text.BeginCatch) .NewLine(Text.Free.RaiserrorS) .NewLine(Text.EndCatch).Terminate(); } sql.Append(Text.Declare).S().Append(Text.Reserved.ReturnValueOuterParam) .Append(Text._As_).Append(Text.Free.EnclosedInt).Terminate().S() .Append(Text.Set).S().Append(Text.Reserved.ReturnValueOuterParam).Append(Text._Equal_) .Append(Text.Zero).Terminate(); // TRY outer wrapper if (root.IsEmbeddedTryCatch) { sql.NewLine(Text.BeginTry); } // output arguments string outputValues = String.Empty; foreach (var argument in outputArguments) { // param in outer wrapper that holds the outer reference string paramOuterName = String.Format("{0}{1}{2}", argument.ParamName, Text.Underscore, Text.Output); // before sql.NewLine(Text.Declare).S() .Append(paramOuterName).Append(Text._As_) .Append(Executable.GetParamDeclaration(argument, false, true)) .Terminate().S() .Append(Text.Set).S().Append(paramOuterName).Append(Text._Equal_); if (argument.TestValue != null) { Testing.AppendTestValue(sql, argument); } else { sql.Append(Mapping.BuildUnchecked(argument.Value)); } sql.TerminateSingle(); // after: return output values outputValues = Text.GenerateSql(100) .NewLineIndent(Text.Comma) .Append(paramOuterName) .Append(Text._As_) .Append(Filter.Delimit(paramOuterName)) .ToString(); } // append last sql code: return value + output values sqlAfter .NewLine(Text.Select).S() .Append(Text.Free.ReturnValue) .Append(Text._As_) .Append(Text.Reserved.ReturnValueColumnName) .Append(outputValues); TryThrow(Text.Method.Pass); sql.NewLine(execSql) .Append(sqlAfter.ToString()) .TerminateSingle(); return(sql.ToString()); }
internal BuildArgs(Executable executable) { Executable = executable; }