示例#1
0
        private static string BuildJoin(IDictionary <string, object> parameters, Join join)
        {
            var builder = new StringBuilder();

            switch (join.JoinOperator)
            {
            case JoinOperation.FullOuterJoin:
                builder.Append("FULL OUTER JOIN ");
                break;

            case JoinOperation.InnerJoin:
                builder.Append("INNER JOIN ");
                break;

            case JoinOperation.LeftJoin:
                builder.Append("LEFT JOIN ");
                break;

            case JoinOperation.RightJoin:
                builder.Append("RIGHT JOIN ");
                break;
            }

            builder.Append(HBDCommon.GetSqlName(join.JoinTable))
            .Append(BuildAlias(join))
            .Append(" ON (")
            .Append(SqlRender.BuildCondition(join.Condition, parameters))
            .Append(")");

            return(builder.ToString());
        }
示例#2
0
        private string BuildInsert(IDictionary <string, object> parameters, InsertQueryBuilder query)
        {
            if (query == null)
            {
                return(null);
            }
            if (query.Tables.Count == 0)
            {
                return(null);
            }
            if (query.Sets.Count == 0)
            {
                return(null);
            }

            var builder = new StringBuilder();
            var result  = BuildInsertSet(parameters, query.Sets);

            builder.Append("INSERT INTO ")
            .Append(Environment.NewLine)
            .Append(BuildTables(parameters, query.Tables))
            .Append($"({string.Join(",", result.Select(n => HBDCommon.GetSqlName(n.Key)))})")
            .Append(Environment.NewLine)
            .Append("VALUES (")
            .Append($"{string.Join(",", result.Select(v => v.Value))}")
            .Append(")");

            return(builder.ToString());
        }
示例#3
0
 private static string BuildField(Field field)
 {
     if (field is FunctionField)
     {
         return(BuildFunctionField((FunctionField)field));
     }
     return(HBDCommon.GetSqlName(field.Name) + BuildAlias(field));
 }
示例#4
0
        private static object BuildUpdateSet(IDictionary <string, object> parameters, KeyValuePair <string, object> set)
        {
            var builder = new StringBuilder();

            var paraName = SqlRender.GetParamertName(parameters, set.Key);

            builder.Append(HBDCommon.GetSqlName(set.Key)).Append(" = ").Append(paraName);
            parameters.Add(paraName, set.Value);

            return(builder.ToString());
        }
示例#5
0
        private static string BuildFunctionField(FunctionField field)
        {
            var builder = new StringBuilder();

            if (field is CustomFunction)
            {
                var c = (CustomFunction)field;
                builder.Append(c.FunctionName.ToUpper())
                .Append($"({BuildSqlValueList(c.Parameters)}) ");
                return(builder.ToString());
            }

            if (field is AverageField)
            {
                builder.Append("AVG");
            }
            if (field is CountField)
            {
                builder.Append("COUNT");
            }
            if (field is LeftField)
            {
                builder.Append("LEFT");
            }
            if (field is RightField)
            {
                builder.Append("RIGHT");
            }
            if (field is MaxField)
            {
                builder.Append("MAX");
            }
            if (field is MinField)
            {
                builder.Append("MIN");
            }
            if (field is SumField)
            {
                builder.Append("SUM");
            }

            builder.Append("(")
            .Append(field.Type == FunctionType.All ? string.Empty : "DISTINCT ")
            .Append(HBDCommon.GetSqlName(field.Name))
            .Append(") ")
            .Append(BuildAlias(field));

            return(builder.ToString());
        }
示例#6
0
 private static string BuildAlias(Aliasable alias)
 => string.IsNullOrWhiteSpace(alias.Alias) ? string.Empty : HBDCommon.GetSqlName(alias.Alias);
示例#7
0
 private static string BuildOrderBy(IList <OrderByField> orderBy)
 =>
 string.Join(",",
             orderBy.Select(
                 f =>
                 HBDCommon.GetSqlName(f.Name) + (f.OrderType == OrderType.Ascending ? string.Empty : " DESC")));