public GroupField(SqlRawBuilder sqlRawBuilder, string field)
        {
            this.sqlRawBuilder = sqlRawBuilder;
            this.field         = field;

            this.sqlRawBuilder.GetSQL          += (this.sqlRawBuilder.HasGroupBySelect ? ", " + field : field);
            this.sqlRawBuilder.HasGroupBySelect = true;
        }
        public GroupField(SqlRawBuilder sqlRawBuilder, string[] fields)
        {
            this.sqlRawBuilder = sqlRawBuilder;
            this.fields        = fields;

            string fieldGroupFormat = string.Join(", ", fields.Select(s => s));

            this.sqlRawBuilder.GetSQL          += (this.sqlRawBuilder.HasGroupBySelect ? ", " + fieldGroupFormat : fieldGroupFormat);
            this.sqlRawBuilder.HasGroupBySelect = true;
        }
        public LeftJoin(SqlRawBuilder sqlRawBuilder, string table1, string tableId1, string table2, string tableId2)
        {
            this.sqlRawBuilder         = sqlRawBuilder;
            this.table1                = table1;
            this.tableId1              = tableId1;
            this.table2                = table2;
            this.tableId2              = tableId2;
            this.sqlRawBuilder.GetSQL += (!sqlRawBuilder.HasTable ? string.Format("FROM {0} ", table1) : "") + "LEFT JOIN " + table2 + " ON " + table1 + "." + tableId1 + " = " + table2 + "." + tableId2 + " ";

            sqlRawBuilder.HasTable = true;
        }
        public Not(SqlRawBuilder sqlRawBuilder, string field, ConditionOperatorEnum operatorEnum, string value)
        {
            this.sqlRawBuilder = sqlRawBuilder;
            this.field         = field;

            if (this.sqlRawBuilder.HasCondition)
            {
                this.sqlRawBuilder.GetSQL += " NOT ";
            }
            this.sqlRawBuilder.GetSQL      += (new FormatCondition(field, operatorEnum, value)).Raw;
            this.sqlRawBuilder.HasCondition = true;
        }
        public Field(SqlRawBuilder sqlRawBuilder, string[] fields, FieldFormatEnum fieldFormatEnum)
        {
            this.sqlRawBuilder = sqlRawBuilder;
            this.fields        = fields;

            string fieldGroupFormat = string.Join(", ", fields.Select(s =>
                                                                      (fieldFormatEnum == FieldFormatEnum.Count) ? string.Format("COUNT({0}) AS {0}", s)
            : (fieldFormatEnum == FieldFormatEnum.Sum) ? string.Format("SUM({0}) AS {0}", s)
            : (fieldFormatEnum == FieldFormatEnum.Avg) ? string.Format("AVG({0}) AS {0}", s)
            : s));

            this.sqlRawBuilder.GetSQL   += (this.sqlRawBuilder.HasSelect ? ", " + fieldGroupFormat : fieldGroupFormat) + " ";
            this.sqlRawBuilder.HasSelect = true;
        }
        public OrCommand(SqlRawBuilder sqlRawBuilder, string field, ConditionOperatorEnum conditionOperator, string value)
        {
            this.sqlRawBuilder     = sqlRawBuilder;
            this.field             = field;
            this.conditionOperator = conditionOperator;
            this.value             = value;

            if (this.sqlRawBuilder.HasCondition)
            {
                this.sqlRawBuilder.GetSQL += " OR ";
            }
            this.sqlRawBuilder.GetSQL      += new FormatCondition(field, conditionOperator, value).Raw;
            this.sqlRawBuilder.HasCondition = true;
        }
        public Field(SqlRawBuilder sqlRawBuilder, string field, FieldFormatEnum fieldFormatEnum)
        {
            this.sqlRawBuilder = sqlRawBuilder;
            this.field         = field;

            string fieldFormat =
                (fieldFormatEnum == FieldFormatEnum.Count) ? string.Format("COUNT({0}) AS {0}", field)
                : (fieldFormatEnum == FieldFormatEnum.Sum) ? string.Format("SUM({0}) AS {0}", field)
                : (fieldFormatEnum == FieldFormatEnum.Avg) ? string.Format("AVG({0}) AS {0}", field)
                : (fieldFormatEnum == FieldFormatEnum.Min) ? string.Format("MIN({0}) AS {0}", field)
                : (fieldFormatEnum == FieldFormatEnum.Max) ? string.Format("MAX({0}) AS {0}", field)
                : field;

            this.sqlRawBuilder.GetSQL   += (this.sqlRawBuilder.HasSelect ? ", " + fieldFormat : fieldFormat) + " ";
            this.sqlRawBuilder.HasSelect = true;
        }
        public UpdateBuilder(SqlRawBuilder sqlRawBuilder, string table, IDictionary <string, string> updates)
        {
            this.sqlRawBuilder = sqlRawBuilder;
            this.table         = table;
            this.updates       = updates;

            string updatesRaw = string.Empty;

            foreach (KeyValuePair <string, string> item in updates)
            {
                if (!string.IsNullOrEmpty(updatesRaw))
                {
                    updatesRaw += ", ";
                }
                updatesRaw += item.Key + "=" + item.Value;
            }

            this.sqlRawBuilder.GetSQL += "UPDATE " + table + updatesRaw;
        }
 public OrderBy(SqlRawBuilder sqlRawBuilder, string order, SortingEnum sortingEnum = SortingEnum.Asc)
 {
     this.sqlRawBuilder         = sqlRawBuilder;
     this.order                 = order;
     this.sqlRawBuilder.GetSQL += " ORDER BY " + order + (sortingEnum == SortingEnum.Desc ? " DESC" : "");
 }
 public CommandBuilder(SqlRawBuilder sqlRawBuilder)
 {
     this.sqlRawBuilder = sqlRawBuilder;
 }
 public Where(SqlRawBuilder sqlRawBuilder)
 {
     this.sqlRawBuilder         = sqlRawBuilder;
     this.sqlRawBuilder.GetSQL += " WHERE ";
 }
 public Having(SqlRawBuilder sqlRawBuilder)
 {
     this.sqlRawBuilder         = sqlRawBuilder;
     this.sqlRawBuilder.GetSQL += " HAVING ";
 }
 public DeleteBuilder(SqlRawBuilder sqlRawBuilder, string table)
 {
     this.sqlRawBuilder = sqlRawBuilder;
     this.table         = table;
 }
 public InsertBuilder(SqlRawBuilder sqlRawBuilder, string table, IDictionary <string, string> values)
 {
     this.sqlRawBuilder = sqlRawBuilder;
     this.table         = table;
     this.values        = values;
 }
 public GroupBy(SqlRawBuilder sqlRawBuilder)
 {
     this.sqlRawBuilder         = sqlRawBuilder;
     this.sqlRawBuilder.GetSQL += " GROUP BY ";
 }
 public Table(SqlRawBuilder sqlRawBuilder, string table)
 {
     this.sqlRawBuilder         = sqlRawBuilder;
     this.table                 = table;
     this.sqlRawBuilder.GetSQL += " FROM " + table;
 }
 public OrderBy(SqlRawBuilder sqlRawBuilder, string[] orders, SortingEnum sortingEnum = SortingEnum.Asc)
 {
     this.sqlRawBuilder         = sqlRawBuilder;
     this.orders                = orders;
     this.sqlRawBuilder.GetSQL += " ORDER BY " + string.Join(", ", orders) + (sortingEnum == SortingEnum.Desc ? " DESC" : "");
 }
 public SelectBuilder(SqlRawBuilder sqlRawBuilder)
 {
     this.sqlRawBuilder        = sqlRawBuilder;
     this.sqlRawBuilder.GetSQL = "SELECT ";
 }