Пример #1
0
        private static string GetWhereClauseItem(InterpolationArgs args)
        {
            if (args.TemplateName == "SELECT" || args.TemplateName == "COUNT")
            {
                string conjunction = GetConjunction(args, string.Empty, new string(' ', 4), "AND ");

                return string.Format(
                    "{1}{2}({3} IS NULL OR {3} = {4}){0}",
                    args.ColumnIndex == args.Columns.Count - 1 ? string.Empty : Environment.NewLine,
                    args.ColumnIndex == 0 ? string.Empty : args.IndentString,
                    conjunction,
                    GetParameter(args),
                    GetColumnWithTableAlias(args)
                );
            }
            else if (args.TemplateName == "UPDATE")
            {
                string conjunction = GetConjunction(args, string.Empty, new string(' ', 4), "AND ");

                return string.Format(
                    "{1}{2}({3} = {4}){0}",
                    args.ColumnIndex == args.Columns.Count - 1 ? string.Empty : Environment.NewLine,
                    args.ColumnIndex == 0 ? string.Empty : args.IndentString,
                    conjunction,
                    GetParameter(args),
                    GetColumn(args)
                );
            }
            else if (args.TemplateName == "DELETE")
            {
                string column = GetColumn(args);

                string conjunction = GetConjunction(
                    args,
                    dr => args.IsPrimaryKey(dr["COLUMN_NAME"].ToString()),
                    string.Empty,
                    new string(' ', 4),
                    "AND "
                );

                string endLine = args.IsLastPrimaryKey(column) ? string.Empty : Environment.NewLine;

                string item = string.Format(
                    "{1}{2}({3} = {4}){0}",
                    endLine,
                    args.ColumnIndex == 0 ? string.Empty : args.IndentString,
                    conjunction,
                    GetParameter(args),
                    GetColumn(args)
                );

                return args.IsPrimaryKey(column) ? item : string.Empty;
            }
            else
            {
                return "??WhereClauseItem??";
            }
        }
Пример #2
0
 private static void GetParameterListItemPunc(InterpolationArgs args, string column, out string conjunction, out string indent, out string endLine)
 {
     if (args.TemplateName == "DELETE")
     {
         conjunction = GetConjunction(args, dr => args.IsPrimaryKey(dr["COLUMN_NAME"].ToString()), string.Empty, " ", ",");
         indent = args.IsFirstPrimaryKey(column) ? string.Empty : args.IndentString;
         endLine = args.IsLastPrimaryKey(column) ? string.Empty : Environment.NewLine;
     }
     else if (args.TemplateName == "INSERT")
     {
         conjunction = GetConjunction(args, dr => !args.IsIdentity(dr["COLUMN_NAME"].ToString()), string.Empty, " ", ",");
         indent = args.IsFirstNonIdentity(column) ? string.Empty : args.IndentString;
         endLine = args.IsLastNonIdentity(column) ? string.Empty : Environment.NewLine;
     }
     else
     {
         conjunction = GetConjunction(args, string.Empty, " ", ",");
         indent = args.ColumnIndex == 0 ? string.Empty : args.IndentString;
         endLine = args.ColumnIndex == args.Columns.Count - 1 ? string.Empty : Environment.NewLine;
     }
 }