示例#1
0
        private string CommandText(string tableBracket)
        {
            var columnBracket = Sqls.TableAndColumnBracket(
                tableBracket: tableBracket, columnBracket: ColumnBracket);

            switch (Function)
            {
            case Sqls.Functions.Count:
                return("count(*)");

            case Sqls.Functions.Sum:
                return("sum(" + columnBracket + ")");

            case Sqls.Functions.Min:
                return("min(" + columnBracket + ")");

            case Sqls.Functions.Max:
                return("max(" + columnBracket + ")");

            case Sqls.Functions.Avg:
                return("avg(" + columnBracket + ")");

            default:
                return(columnBracket);
            }
        }
示例#2
0
 private string TableAndColumnBracket(
     string tableBracket, string columnBracket, bool select)
 {
     return(select
         ? Sqls.TableAndColumnBracket(tableBracket, columnBracket)
         : columnBracket);
 }
示例#3
0
 private string Functions(string tableBracket)
 {
     return(Function.ToString().ToLower() +
            "(" + Sqls.TableAndColumnBracket(
                tableBracket: tableBracket,
                columnBracket: ColumnBracket) + ")");
 }
示例#4
0
        private string Sql_Sub(
            SqlContainer sqlContainer,
            SqlCommand sqlCommand,
            IEnumerable <string> left,
            Sqls.TableTypes tableType,
            int?commandCount)
        {
            var commandText = Sub.GetCommandText(
                sqlContainer: sqlContainer,
                sqlCommand: sqlCommand,
                prefix: "_sub",
                commandCount: commandCount);

            return(left != null
                ? left.Select(columnBracket =>
                              Sqls.TableAndColumnBracket(
                                  tableName : TableName,
                                  tableType : tableType,
                                  columnBracket : columnBracket) +
                              Operator +
                              "(" + commandText + ")")
                   .Join(MultiColumnOperator)
                   : Value == null
                    ? "(" + commandText + ")"
                   : "(" + commandText + Operator + Value + ")");
        }
        private string CommandText(
            ISqlObjectFactory factory,
            string tableBracket)
        {
            var columnBracket = Sqls.TableAndColumnBracket(
                tableBracket: tableBracket, columnBracket: ColumnBracket);

            switch (Function)
            {
            case Sqls.Functions.Count:
                return("count(*)");

            case Sqls.Functions.Sum:
                return("sum(" + columnBracket + ")");

            case Sqls.Functions.Min:
                return("min(" + columnBracket + ")");

            case Sqls.Functions.Max:
                return("max(" + columnBracket + ")");

            case Sqls.Functions.Avg:
                return($"avg({factory.Sqls.IsNull}({columnBracket}, 0))");

            default:
                return(columnBracket);
            }
        }
示例#6
0
 private string Functions(Sqls.TableTypes tableType)
 {
     return(Function.ToString().ToLower() +
            "(" + Sqls.TableAndColumnBracket(
                tableName: TableName,
                tableType: tableType,
                columnBracket: ColumnBracket) + ")");
 }
示例#7
0
 private string Sql_General(
     string columnBracket, Sqls.TableTypes tableType, int?commandCount)
 {
     return
         (Sqls.TableAndColumnBracket(
              tableName: TableName,
              tableType: tableType,
              columnBracket: columnBracket) +
          Operator +
          Variable(commandCount: commandCount));
 }
示例#8
0
 public void BuildCommandText(StringBuilder commandText)
 {
     if (this.Any())
     {
         commandText.Append("group by ", this.Select(o =>
                                                     Sqls.TableAndColumnBracket(
                                                         tableBracket: Sqls.GetTableBracket(o.TableName),
                                                         columnBracket: o.ColumnBracket))
                            .Join(), " ");
     }
 }
示例#9
0
 public void BuildCommandText(StringBuilder commandText, Sqls.TableTypes tableType)
 {
     if (this.Any())
     {
         commandText.Append("group by ", this.Select(o =>
                                                     Sqls.TableAndColumnBracket(
                                                         tableName: o.TableName,
                                                         tableType: tableType,
                                                         columnBracket: o.ColumnBracket))
                            .Join(), " ");
     }
 }
示例#10
0
        public string Sql(
            ISqlObjectFactory factory,
            SqlContainer sqlContainer,
            ISqlCommand sqlCommand,
            string tableBracket,
            Sqls.TableTypes tableType)
        {
            var orderType = " " + OrderType.ToString().ToLower();

            if (!Raw.IsNullOrEmpty())
            {
                return(Raw);
            }
            else if (Sub != null)
            {
                return(Sql_Sub(
                           factory: factory,
                           sqlContainer: sqlContainer,
                           sqlCommand: sqlCommand,
                           orderType: orderType));
            }
            else
            {
                string columnBracket = Sqls.TableAndColumnBracket(
                    tableBracket: tableType == Sqls.TableTypes.NormalAndHistory
                        ? string.Empty
                        : tableBracket,
                    columnBracket: ColumnBracket);
                switch (Function)
                {
                case Sqls.Functions.Count:
                case Sqls.Functions.Sum:
                case Sqls.Functions.Min:
                case Sqls.Functions.Max:
                    return
                        (Function.ToString().ToLower() +
                         "(" +
                         columnBracket +
                         ")" +
                         orderType);

                case Sqls.Functions.Avg:
                    return($"avg({factory.Sqls.IsNull}({columnBracket}, 0)) {orderType}");

                default:
                    return(IsNullValue.IsNullOrEmpty()
                            ? columnBracket + orderType
                            : $"{factory.Sqls.IsNull}({columnBracket}, {IsNullValue}) {orderType}");
                }
            }
        }
示例#11
0
 private string ReplacedSql(
     SqlContainer sqlContainer,
     SqlCommand sqlCommand,
     IEnumerable <string> left,
     Sqls.TableTypes tableType,
     int?commandCount)
 {
     return(left != null
         ? left.Select(columnBracket =>
                       Sqls.TableAndColumnBracket(
                           tableName : TableName,
                           tableType : tableType,
                           columnBracket : columnBracket) +
                       ReplacedRaw(commandCount : commandCount))
            .Join(MultiColumnOperator)
            : Raw.Replace("#CommandCount#", commandCount.ToString()));
 }
示例#12
0
 private string Sql_General(
     string columnBracket,
     Sqls.TableTypes tableType,
     int?commandCount,
     IEnumerable <string> valueCollection)
 {
     return(valueCollection
            .Select((o, i) =>
                    Sqls.TableAndColumnBracket(
                        tableName: TableName,
                        tableType: tableType,
                        columnBracket: columnBracket) +
                    Operator +
                    Variable(
                        commandCount: commandCount,
                        paramCount: i.ToString() + "_"))
            .Join(MultiParamOperator));
 }
        public string Sql(
            ISqlObjectFactory factory,
            SqlContainer sqlContainer,
            ISqlCommand sqlCommand,
            string tableBracket,
            Sqls.TableTypes tableType)
        {
            var orderType = " " + OrderType.ToString().ToLower();

            if (Sub != null)
            {
                return(Sql_Sub(
                           factory: factory,
                           sqlContainer: sqlContainer,
                           sqlCommand: sqlCommand,
                           orderType: orderType));
            }
            else
            {
                string columnBracket = Sqls.TableAndColumnBracket(
                    tableBracket: tableType == Sqls.TableTypes.NormalAndHistory
                        ? string.Empty
                        : tableBracket,
                    columnBracket: ColumnBracket);
                switch (Function)
                {
                case Sqls.Functions.Count:
                case Sqls.Functions.Sum:
                case Sqls.Functions.Min:
                case Sqls.Functions.Max:
                case Sqls.Functions.Avg:
                    return
                        (Function.ToString().ToLower() +
                         "(" +
                         columnBracket +
                         ")" +
                         orderType);

                default:
                    return(columnBracket + orderType);
                }
            }
        }