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()); }
// 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()); }