Пример #1
0
        internal string BuildExceptionReport(object[] rkValues, object rowversion)
        {
            if (HasRowversion && rowversion == null)
            {
                return(String.Format("{0} = null", RowversionColumn.Name));
            }

            var builder = new StringBuilder();
            var i       = 0;

            foreach (var column in SortedRKColumns)
            {
                var value = Mapping.Build(rkValues[i++], column.DataType);
                if (i == 1)
                {
                    builder.Append(String.Format("{0} = {1}", column.Name.Sql, value));
                }
                else
                {
                    builder.NewLine(String.Format("   {0} = {1}", column.Name.Sql, value));
                }
            }

            return(builder.ToString());
        }
Пример #2
0
        private void OnCellFormating(object o, DataGridViewCellFormattingEventArgs e)
        {
            // null
            if (e.Value == null)
            {
                e.Value = Wall.Text.Null;
                e.CellStyle.ForeColor = _defaultNullColor;
                e.FormattingApplied   = true;
                return;
            }

            // format DateTime as ISO 8601 (string)
            if (e.Value is DateTime)
            {
                var    value = (DateTime)e.Value;
                object value2;

                // is clean date
                if (value.Date == value)
                {
                    value2 = String.Format("{0:yyyy-MM-dd}", e.Value);
                }
                else
                {
                    value2 = String.Format("{0:yyyy-MM-dd HH:mm:ss.fffffff}", e.Value);
                }
                e.Value             = value2;
                e.FormattingApplied = true;
                return;
            }

            // DateTimeOffset
            if (e.Value is DateTimeOffset)
            {
                object value2 = String.Format("{0:o}", e.Value);
                e.Value             = value2;
                e.FormattingApplied = true;
                return;
            }

            // byte array
            if (e.Value is System.Byte[])
            {
                var value2 = Mapping.Build(e.Value, Mapping.DefaultBinaryType);
                e.Value             = value2;
                e.FormattingApplied = true;
                return;
            }
        }
Пример #3
0
 private static void AppendColumnValue(StringBuilder sql, object value, int index, DataType dataType, bool isSqlVariantFirstRow = false)
 {
     if (isSqlVariantFirstRow)
     {
         AppendColumnAsSqlVariant(sql,
                                  Mapping.Build(value, dataType),
                                  String.Format("{0}{1}", Text.ColumnShortName, index));
     }
     else
     {
         AppendColumn(sql,
                      Mapping.Build(value, dataType),
                      String.Format("{0}{1}", Text.ColumnShortName, index));
     }
 }
Пример #4
0
        internal Expression BuildRKPredicate(object[] rkValues, int index, bool parameterization = true)
        {
            StringBuilder builder = null;
            int           i       = 0;

            foreach (var column in SortedRKColumns)
            {
                string expressionStr;
                if (rkValues[i] == null)
                {
                    expressionStr = String.Format("([{0}].{1} IS NULL)",
                                                  index, column.Name);
                }
                else
                {
                    if (parameterization)
                    {
                        expressionStr = String.Format("([{0}].{1} = @o{2})",
                                                      index, column.Name, i + 1);
                    }
                    else
                    {
                        var value = rkValues[i];
                        expressionStr = String.Format("([{0}].{1} = {2})",
                                                      index, column.Name, Mapping.Build(value, column.DataType));
                    }
                }

                if (builder == null)
                {
                    builder = Text.GenerateSql(200);
                }
                else
                {
                    builder.Append(Text._And_);
                }

                builder.Append(expressionStr);
                ++i;
            }

            return(builder.ToString().E());
        }
Пример #5
0
        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());
        }
Пример #6
0
        internal void BuildParamAppendix(BuildArgs buildArgs)
        {
            _paramDeclaration = new StringBuilder();
            _paramAssignment  = new StringBuilder();

            if (Admin.IsValueParameterizationOn && !buildArgs.IsTesting)
            {
                _rootCompilable.ImplicitParams.ForEach(param =>
                {
                    _arguments.Add(param.ParameterizedValue);
                });
            }

            // return value
            _paramDeclaration.Append(Text.Reserved.ReturnValueInnerParam).S()
            .Append(Text.Free.EnclosedInt).S().Append(Text.Output);
            _paramAssignment.Append(Text.Reserved.ReturnValueInnerParam)
            .Append(Text._Equal_)
            .Append(Text.Reserved.ReturnValueOuterParam).S()
            .Append(Text.Output);

            // auto add arguments of optional params (if not passed)
            _rootCompilable.ExplicitParams.Where(param => param.IsOptional).ToList()
            .ForEach(param =>
            {
                if (!CheckArgumentByName(param.Name))
                {
                    _arguments.Add(param.Default);
                }
            });

            // exclude inline params, table variable, temp tables and bulk tables
            bool paramSeparator = false;

            _arguments.Where(argument => argument.DT.IsNotInliner() &&
                             !argument.DT.IsVTB())
            .ToList()
            .ForEach(argument =>
            {
                // param declaration
                _paramDeclaration.NewLine(Text.Comma);
                _paramDeclaration
                .Append(argument.ParamName)
                .Append(Text._As_)
                .Append(GetParamDeclaration(argument, true, false));

                string declarationOutput = String.Empty;
                if (argument.IsParamOutput)
                {
                    declarationOutput = Text.OneSpace + Text.Output;
                }
                _paramDeclaration.Append(declarationOutput);

                // marks the beginning of client params
                if (!paramSeparator && argument.ParamName != Text.Reserved.ReturnValueInnerParam)
                {
                    _paramAssignment.NewLine()
                    .NewLine(Text.Free.Params);
                    paramSeparator = true;
                }

                _paramAssignment.NewLine(Text.Comma);

                // argument is a variable:
                //   note:
                //     variables can only be passed in the inner call, otherwise they are treated as string values
                if (argument.IsPassedVariable && _inner)
                {
                    _paramAssignment.Append(argument.ParamName)
                    .Append(Text.Equal)
                    .Append(argument.Value);
                }
                // argument is a value:
                else
                {
                    _paramAssignment.Append(argument.ParamName)
                    .Append(Text.Equal);

                    if (argument.Original is View)
                    {
                        // note: inner table param has the same name as outer table param
                        _paramAssignment.Append(argument.ParamName);
                    }
                    else if (argument.IsOutput)
                    {
                        _paramAssignment.Append(argument.ParamName)
                        .Append(Text.Underscore)
                        .Append(Text.Output);
                    }
                    else
                    {
                        // the test value has the advantage over the regular value
                        if (argument.TestValue != null)
                        {
                            Testing.AppendTestValue(_paramAssignment, argument);
                        }
                        else
                        {
                            if (argument.DataType != null)
                            {
                                _paramAssignment.Append(Mapping.Build(argument.Value, argument.DataType));
                            }
                            else
                            {
                                _paramAssignment.Append(Mapping.BuildUnchecked(argument.Value));
                            }
                        }
                    }
                }

                string assignmentOutput = String.Empty;
                if (argument.IsOutput)
                {
                    assignmentOutput = Text.OneSpace + Text.Output;
                }

                _paramAssignment.Append(assignmentOutput);
            });

            if (chainException != null)
            {
                TryThrow(Text.Method.Pass);
            }
        }
Пример #7
0
 internal static string BuildClr(string arg, BuildContext buildContext)
 {
     return(arg.Parameterize(buildContext, Mapping.DefaultStringType) ?? Mapping.Build(arg, Mapping.DefaultStringType));
 }