示例#1
0
        internal protected void OrderBy()
        {
            var dic = DC.Parameters.FirstOrDefault(it => it.Action == ActionEnum.From);
            var tbm = DC.XC.GetTableModel(dic != null ? dic.TbMType : DC.TbM1);

            if (DC.Parameters.Any(it => it.Action == ActionEnum.OrderBy))
            {
                CRLF(X); X.Append("order by"); Spacing(X); OrderByParams();
            }
            else
            {
                if (!IsPaging(DC))
                {
                    return;
                }

                var col = DbSql.GetIndex(tbm.TbCols);
                if (col != null)
                {
                    CRLF(X); X.Append("order by"); Spacing(X);
                    if (DC.Crud == CrudEnum.Join)
                    {
                        DbSql.Column(dic.TbAlias, col.ColumnName, X); Spacing(X); X.Append("desc");
                    }
                    else
                    {
                        DbSql.Column(string.Empty, col.ColumnName, X); Spacing(X); X.Append("desc");
                    }
                }
            }
        }
示例#2
0
 private void SelectSpecialDateFormatCol(DicParam dic)
 {
     if (dic.Crud == CrudEnum.Join)
     {
         if (dic.Option == OptionEnum.Column)
         {
             Function(dic.Func, X, DC); LeftRoundBracket(X); DbSql.Column(dic.TbAlias, dic.TbCol, X); Comma(X); StringConst(dic.Format, X); RightRoundBracket(X);
         }
         else if (dic.Option == OptionEnum.ColumnAs)
         {
             Function(dic.Func, X, DC); LeftRoundBracket(X); DbSql.Column(dic.TbAlias, dic.TbCol, X); Comma(X); StringConst(dic.Format, X); RightRoundBracket(X);
             As(X); DbSql.ColumnAlias(dic.TbColAlias, X);
         }
     }
     else if (dic.Crud == CrudEnum.Query)
     {
         if (dic.Option == OptionEnum.Column)
         {
             Function(dic.Func, X, DC); LeftRoundBracket(X); DbSql.Column(string.Empty, dic.TbCol, X); Comma(X); StringConst(dic.Format, X); RightRoundBracket(X);
         }
         else if (dic.Option == OptionEnum.ColumnAs)
         {
             Function(dic.Func, X, DC); LeftRoundBracket(X); DbSql.Column(string.Empty, dic.TbCol, X); Comma(X); StringConst(dic.Format, X); RightRoundBracket(X);
             As(X); DbSql.ColumnAlias(dic.TbColAlias, X);
         }
     }
 }
示例#3
0
        internal protected void Sum()
        {
            Spacing(X);
            var col = DC.Parameters.FirstOrDefault(it => IsSelectColumnParam(it));
            var sum = col.Columns.FirstOrDefault(it => it.Func == FuncEnum.Sum)
                      ?? col.Columns.FirstOrDefault(it => it.Func == FuncEnum.SumNullable);

            if (sum != null)
            {
                var tbAlias = sum.Crud == CrudEnum.Query
                                      ? string.Empty
                                      : sum.Crud == CrudEnum.Join
                                        ? sum.TbAlias
                                        : string.Empty;
                Function(sum.Func, X, DC);
                LeftRoundBracket(X);
                if (sum.Func == FuncEnum.Sum)
                {
                    DbSql.Column(tbAlias, sum.TbCol, X);
                }
                else if (sum.Func == FuncEnum.SumNullable)
                {
                    DbSql.ColumnReplaceNullValueForSum(tbAlias, sum.TbCol, X);
                }
                RightRoundBracket(X);
            }
        }
示例#4
0
        /****************************************************************************************************************************/

        private void JoinX()
        {
            Spacing(X);
            foreach (var dp in DC.Parameters)
            {
                if (dp.Crud != CrudEnum.Join)
                {
                    continue;
                }
                switch (dp.Action)
                {
                case ActionEnum.From:
                    /* 已处理 */
                    break;

                case ActionEnum.InnerJoin:
                case ActionEnum.LeftJoin:
                    var tbm = DC.XC.GetTableModel(dp.TbMType);
                    CRLF(X); Tab(X);
                    Action(dp.Action, X, DC); Spacing(X); DbSql.TableX(tbm.TbName, X); As(X); DbSql.TableXAlias(dp.TbAlias, X);
                    break;

                case ActionEnum.On:
                    CRLF(X); Tab(X); Tab(X);
                    Action(dp.Action, X, DC); Spacing(X); DbSql.Column(dp.TbAlias, dp.TbCol, X); Compare(dp.Compare, X, DC); DbSql.Column(dp.TableAliasTwo, dp.ColumnTwo, X);
                    break;
                }
            }
        }
示例#5
0
 private void SelectSpecialNoFuncCol(DicParam dic)
 {
     if (dic.Crud == CrudEnum.Join)
     {
         if (dic.Option == OptionEnum.Column)
         {
             DbSql.Column(dic.TbAlias, dic.TbCol, X);
         }
         else if (dic.Option == OptionEnum.ColumnAs)
         {
             DbSql.Column(dic.TbAlias, dic.TbCol, X); As(X); DbSql.ColumnAlias(dic.TbColAlias, X);
         }
     }
     else if (dic.Crud == CrudEnum.Query)
     {
         if (dic.Option == OptionEnum.Column)
         {
             DbSql.Column(string.Empty, dic.TbCol, X);
         }
         else if (dic.Option == OptionEnum.ColumnAs)
         {
             DbSql.Column(string.Empty, dic.TbCol, X); As(X); DbSql.ColumnAlias(dic.TbColAlias, X);
         }
     }
 }
示例#6
0
        /****************************************************************************************************************************/

        private void CompareProcess(DicParam db)
        {
            if (db.Compare == CompareXEnum.In ||
                db.Compare == CompareXEnum.NotIn)
            {
                InProcess(db);
            }
            else if (db.Compare == CompareXEnum.Like ||
                     db.Compare == CompareXEnum.NotLike)
            {
                LikeProcess(db);
            }
            else
            {
                Spacing(X);
                if (db.Crud == CrudEnum.Join)
                {
                    DbSql.Column(db.TbAlias, db.TbCol, X);
                }
                else if (DC.IsSingleTableOption())
                {
                    DbSql.Column(string.Empty, db.TbCol, X);
                }
                Compare(db.Compare, X, DC); DbSql.DbParam(db.Param, X);
            }
        }
示例#7
0
 private void IsNullProcess(DicParam db)
 {
     Spacing(X);
     if (db.Crud == CrudEnum.Join)
     {
         DbSql.Column(db.TbAlias, db.TbCol, X);
     }
     else if (DC.IsSingleTableOption())
     {
         DbSql.Column(string.Empty, db.TbCol, X);
     }
     Spacing(X); Option(db.Option, X, DC);
 }
示例#8
0
 private void LikeProcess(DicParam db)
 {
     Spacing(X);
     if (db.Crud == CrudEnum.Join)
     {
         DbSql.Column(db.TbAlias, db.TbCol, X);
     }
     else if (DC.IsSingleTableOption())
     {
         DbSql.Column(string.Empty, db.TbCol, X);
     }
     Compare(db.Compare, X, DC); LikeStrHandle(db);
 }
示例#9
0
 private void InProcess(DicParam db)
 {
     Spacing(X);
     if (db.Crud == CrudEnum.Join)
     {
         DbSql.Column(db.TbAlias, db.TbCol, X);
     }
     else if (DC.IsSingleTableOption())
     {
         DbSql.Column(string.Empty, db.TbCol, X);
     }
     Spacing(X);
     Compare(db.Compare, X, DC); LeftRoundBracket(X); InParams(db.InItems); RightRoundBracket(X);
 }
示例#10
0
 private void ToStringCol(string tbAlias, string tbCol, ToStringEnum func)
 {
     if (func == ToStringEnum.concat)
     {
         X.Append("concat"); LeftRoundBracket(X); DbSql.Column(tbAlias, tbCol, X); Comma(X); StringConst(string.Empty, X); RightRoundBracket(X);
     }
     else if (func == ToStringEnum.add)
     {
         StringConst(string.Empty, X); X.Append('+'); DbSql.Column(tbAlias, tbCol, X);
     }
     else
     {
         throw XConfig.EC.Exception(XConfig.EC._095, $"函数 -- {func.ToString()} -- 未能解析!");
     }
 }
示例#11
0
 private void TrimProcess(DicParam db)
 {
     Spacing(X);
     Function(db.Func, X, DC); LeftRoundBracket(X);
     if (db.Crud == CrudEnum.Join)
     {
         DbSql.Column(db.TbAlias, db.TbCol, X);
     }
     else if (DC.IsSingleTableOption())
     {
         DbSql.Column(string.Empty, db.TbCol, X);
     }
     RightRoundBracket(X);
     Compare(db.Compare, X, DC); DbSql.DbParam(db.Param, X);
 }
示例#12
0
        internal protected void UpdateColumn()
        {
            //
            var list = DC.Parameters.Where(it => it.Action == ActionEnum.Update)?.ToList();

            if (list == null || list.Count == 0)
            {
                throw XConfig.EC.Exception(XConfig.EC._053, "没有设置任何要更新的字段!");
            }

            //
            Spacing(X);
            var i = 0;

            foreach (var item in list)
            {
                i++;
                if (item.Option == OptionEnum.ChangeAdd ||
                    item.Option == OptionEnum.ChangeMinus)
                {
                    if (i != 1)
                    {
                        CRLF(X); Tab(X);
                    }
                    DbSql.Column(string.Empty, item.TbCol, X); Equal(X); DbSql.Column(string.Empty, item.TbCol, X); Option(item.Option, X, DC); DbSql.DbParam(item.Param, X);
                }
                else if (item.Option == OptionEnum.Set)
                {
                    if (i != 1)
                    {
                        CRLF(X); Tab(X);
                    }
                    DbSql.Column(string.Empty, item.TbCol, X); Option(item.Option, X, DC); DbSql.DbParam(item.Param, X);
                }
                else
                {
                    throw XConfig.EC.Exception(XConfig.EC._009, $"{item.Action}-{item.Option}");
                }
                if (i != list.Count)
                {
                    Comma(X);
                }
            }
        }
示例#13
0
        internal protected void OrderByParams()
        {
            var orders = DC.Parameters.Where(it => IsOrderByParam(it)).ToList();
            var i      = 0;

            foreach (var o in orders)
            {
                i++;
                if (o.Func == FuncEnum.None)
                {
                    if (DC.Crud == CrudEnum.Join)
                    {
                        DbSql.Column(o.TbAlias, o.TbCol, X); Spacing(X); Option(o.Option, X, DC);
                    }
                    else
                    {
                        DbSql.Column(string.Empty, o.TbCol, X); Spacing(X); Option(o.Option, X, DC);
                    }
                }
                else if (o.Func == FuncEnum.CharLength)
                {
                    if (DC.Crud == CrudEnum.Join)
                    {
                        Function(o.Func, X, DC); LeftRoundBracket(X); DbSql.Column(o.TbAlias, o.TbCol, X); RightRoundBracket(X); Spacing(X); Option(o.Option, X, DC);
                    }
                    else
                    {
                        Function(o.Func, X, DC); LeftRoundBracket(X); DbSql.Column(string.Empty, o.TbCol, X); RightRoundBracket(X); Spacing(X); Option(o.Option, X, DC);
                    }
                }
                else
                {
                    throw XConfig.EC.Exception(XConfig.EC._013, $"{o.Action}-{o.Option}-{o.Func}");
                }
                if (i != orders.Count)
                {
                    Comma(X); CRLF(X); Tab(X);
                }
            }
        }
示例#14
0
 internal protected void CountNoneDistinct(List <DicParam> cols)
 {
     if (cols == null ||
         cols.Count <= 0)
     {
         X.Append(" count(*) ");
     }
     else if (cols.Count == 1)
     {
         var count = cols.First().Columns?.FirstOrDefault(it => IsCountParam(it));
         if (count != null)
         {
             if ("*".Equals(count.TbCol, StringComparison.OrdinalIgnoreCase))
             {
                 Function(count.Func, X, DC); LeftRoundBracket(X); Star(X); RightRoundBracket(X);
             }
             else
             {
                 Function(count.Func, X, DC); LeftRoundBracket(X);
                 if (count.Crud == CrudEnum.Query)
                 {
                     DbSql.Column(string.Empty, count.TbCol, X);
                 }
                 else if (count.Crud == CrudEnum.Join)
                 {
                     DbSql.Column(count.TbAlias, count.TbCol, X);
                 }
                 RightRoundBracket(X);
             }
         }
         else
         {
             if (cols.First().Columns == null ||
                 cols.First().Columns.Count <= 0)
             {
                 throw XConfig.EC.Exception(XConfig.EC._025, "不应该出现的情况!");
             }
             else if (cols.First().Columns.Count == 1)
             {
                 var col = cols.First().Columns.First();
                 if (col.Crud == CrudEnum.Join &&
                     "*".Equals(col.TbCol, StringComparison.OrdinalIgnoreCase))
                 {
                     CountSetMulti(false, false);
                 }
                 else
                 {
                     Function(FuncEnum.Count, X, DC); LeftRoundBracket(X);
                     if (col.Crud == CrudEnum.Query)
                     {
                         DbSql.Column(string.Empty, col.TbCol, X);
                     }
                     else if (col.Crud == CrudEnum.Join)
                     {
                         DbSql.Column(col.TbAlias, col.TbCol, X);
                     }
                     RightRoundBracket(X);
                 }
             }
             else
             {
                 CountSetMulti(false, false);
             }
         }
     }
     else
     {
         CountSetMulti(false, false);
     }
 }