コード例 #1
0
ファイル: Select.cs プロジェクト: wj60387/hubble
        override public void Finish()
        {
            foreach (object obj in SyntaxList)
            {
                if (obj is SelectField)
                {
                    SelectField selectField = obj as SelectField;

                    if (selectField.BetweenRecord)
                    {
                        this.Begin = selectField.Begin;
                        this.End   = selectField.End;
                    }

                    SelectFields.Add(selectField);
                }
                else if (obj is SelectFrom)
                {
                    SelectFroms.Add(obj as SelectFrom);
                }
                else if (obj is OrderBy)
                {
                    OrderBys.Add(obj as OrderBy);
                }
                else if (obj is Where)
                {
                    Where = obj as Where;
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// 生成order by命令(自动忽略空或空文本)。
 /// </summary>
 /// <param name="field">列,例:aa</param>
 /// <param name="orderby">排序规则</param>
 /// <returns></returns>
 public virtual ISelectCommandBuilder OrderBy(string field, OrderBys orderby)
 {
     if (string.IsNullOrEmpty(field))
     {
         return(this);
     }
     return(OrderBy(_dialect.PreName(field) + " " + EnumExtensions.GetProperty(orderby, "Keyword")));
 }
コード例 #3
0
 public QueryExpression OrderBy(params IOrderExpression[] orderExpressions)
 {
     foreach (IOrderExpression orderExpression in orderExpressions)
     {
         OrderBys.Add(orderExpression);
     }
     return(this);
 }
コード例 #4
0
ファイル: SelectStatement.cs プロジェクト: E024/Swifter
        /// <summary>
        /// 构建 Select 语句信息
        /// </summary>
        /// <param name="mainTable">表</param>
        public SelectStatement(ITable mainTable)
        {
            MainTable = mainTable;

            Columns  = new SelectColumns();
            Joins    = new Joins();
            Where    = new Conditions();
            OrderBys = new OrderBys();
            GroupBys = new GroupBys();
            Having   = new Conditions();
        }
コード例 #5
0
ファイル: QueryBuilder.cs プロジェクト: scbrady/lynicon
 protected virtual string BuildSelectText()
 {
     return("SELECT "
            + SelectModifier + " "
            + GetFieldList()
            + " FROM " + SqlTable
            + (SqlConditionals.Count == 0 ? ""
             : " WHERE " + SqlConditionals.Join(" AND "))
            + (OrderBys.Count == 0 ? ""
             : " ORDER BY " + OrderBys.Join(",")));
 }
コード例 #6
0
ファイル: SqlSelect.cs プロジェクト: cwaldron/CafeLib
        private string BuildOutput(bool includeSelection = true)
        {
            var sb = new StringBuilder();

            var offset = Limit?.Offset ?? 0;
            var fetch  = Limit?.Fetch ?? 0;

            if (includeSelection)
            {
                var topStr = offset == 0 && fetch > 0 ? $"top({fetch}) " : "";
                sb.Append($"select {topStr}{Selection}");
            }

            if (From != null)
            {
                sb.AppendLine();
                sb.Append($"from {From}");
            }

            if (Joins.Count > 0)
            {
                sb.AppendLine();
                sb.Append($"{string.Join(Environment.NewLine, Joins)}");
            }

            if (Where != null)
            {
                sb.AppendLine();
                sb.Append($"where {Where}");
            }

            if (GroupBys.Any())
            {
                sb.AppendLine();
                sb.Append($"group by {GroupBys}");
            }

            if (OrderBys.Any())
            {
                sb.AppendLine();
                sb.Append($"order by {string.Join(", ", OrderBys)}");
            }

            if (Limit != null && Limit.Offset > 0)
            {
                sb.AppendLine();
                sb.Append($"{Limit}");
            }

            sb.AppendLine();

            return(sb.ToString());
        }
コード例 #7
0
        protected override string FormatPagingSql(DbTextWriter writer, Constraint constraint)
        {
            Argument.Assert.IsNotNull(writer, nameof(writer));

            OnWriteSelect(writer);
            OnWriteFrom(writer);
            OnWriteWhere(writer);
            OnWriteGroupBys(writer);
            OnWriteHaving(writer);

            string subQuery = writer.ToString();
            string outerSelectList;
            string orderbylist;

            if (OrderBys.Count == 0 && SelectTable != null)
            {
                if (SelectTable.HasIdentityColumn)
                {
                    OrderBys.Add(new OrderBy(SelectTable.IdentityColumn, OrderByDirection.Asc));
                }
                else if (SelectTable.HasPrimaryKey)
                {
                    foreach (QueryColumn key in SelectTable.PrimaryKey)
                    {
                        OrderBys.Add(new OrderBy(key, OrderByDirection.Asc));
                    }
                }
                else
                {
                    throw new InvalidOperationException("The paging command has no OrderBy column specified and the table has no identity column or primary key defined.");
                }
            }

            using (DbTextWriter outerSelectWriter = new DbTextWriter())
            {
                outerSelectWriter.WriteSelectColumns(Columns);
                outerSelectList = outerSelectWriter.ToString();
            }

            using (DbTextWriter orderByWriter = new DbTextWriter())
            {
                orderByWriter.WriteOrderBy(OrderBys, constraint);
                orderbylist = orderByWriter.ToString();
            }

            Parameters.Add("_pi", constraint.Start);
            Parameters.Add("_ps", constraint.Count);
            return(string.Format(PagingSelectTemplate, outerSelectList, orderbylist, subQuery));
        }
コード例 #8
0
        private string BuildOutput(bool includeSelection = true)
        {
            var sb = new StringBuilder();

            if (includeSelection)
            {
                sb.Append($"select {Selection}");
            }

            if (From != null)
            {
                sb.AppendLine();
                sb.Append($"from {From}");
            }

            if (Joins.Count > 0)
            {
                sb.AppendLine();
                sb.Append($"{string.Join(Environment.NewLine, Joins)}");
            }

            if (Where != null)
            {
                sb.AppendLine();
                sb.Append($"where {Where}");
            }

            if (GroupBys.Any())
            {
                sb.AppendLine();
                sb.Append($"group by {GroupBys}");
            }

            if (OrderBys.Any())
            {
                sb.AppendLine();
                sb.Append($"order by {string.Join(", ", OrderBys)}");
            }

            sb.AppendLine();

            return(sb.ToString());
        }
コード例 #9
0
 private string ConvertToWooOrderBy(OrderBys inputValue)
 {
     return(AttriburteOrderByToWooOrerBy[inputValue]);  // return the string equivalent of the enum OrderBys
 }
コード例 #10
0
        public virtual Condition BuildCondition(Type type, VariableResolver variableResolver = null, IEnumerable <string> validProperties = null, IDictionary <string, string> propertyMapping = null)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }
            var arg = new BuildArgument
            {
                ValidProperties  = validProperties,
                VariableResolver = variableResolver,
                EvaluationType   = type,
                PropertyMapping  = propertyMapping
            };

            var           error         = new ConditionBase.ErrorInfo();
            var           result        = new Condition();
            var           predicates    = new List <LambdaExpression>();
            var           exceptions    = new List <Exception>();
            OrderByClause orderByClause = null;

            if (Filters != null && Filters.Any())
            {
                var filtersResult = Filters.TryBuildPredicate(type, arg);
                if (filtersResult.Succeeded)
                {
                    predicates.Add(filtersResult.Result);
                }
                else
                {
                    if (filtersResult.Exception != null)
                    {
                        exceptions.Add(filtersResult.Exception);
                    }
                }
            }

            if (FilterGroups != null && FilterGroups.Any())
            {
                var filterGroupsResult = FilterGroups.TryBuildPredicate(type, arg);
                if (filterGroupsResult.Succeeded)
                {
                    predicates.Add(filterGroupsResult.Result);
                }
                else
                {
                    if (filterGroupsResult.Exception != null)
                    {
                        exceptions.Add(filterGroupsResult.Exception);
                    }
                }
            }

            if (!string.IsNullOrEmpty(Where))
            {
                var whereResult = ExpressionParser.Parse(Where, type, arg);
                if (whereResult.Succeeded)
                {
                    predicates.Add(whereResult.Result);
                }
                else
                {
                    if (whereResult.Exception != null)
                    {
                        exceptions.Add(whereResult.Exception);
                    }
                }
            }

            if (!string.IsNullOrWhiteSpace(OrderBy))
            {
                var orderByResult = OrderByParser.Parse(OrderBy, arg);
                if (orderByResult.Succeeded)
                {
                    orderByClause = orderByResult.Result;
                }
                else
                {
                    if (orderByResult.Exception != null)
                    {
                        exceptions.Add(orderByResult.Exception);
                    }
                }
            }
            else if (OrderBys != null && OrderBys.Any())
            {
                var orderBysResult = OrderByParser.Parse(OrderBys.ToArray(), arg);
                if (orderBysResult.Succeeded)
                {
                    orderByClause = orderBysResult.Result;
                }
                else
                {
                    if (orderBysResult.Exception != null)
                    {
                        exceptions.Add(orderBysResult.Exception);
                    }
                }
            }

            var isInvalid = arg.InvalidProperties.Any() || arg.InvalidOperators.Any() || arg.InvalidVariables.Any() || exceptions.Any();

            result.IsValid = !isInvalid;
            if (isInvalid)
            {
                error.EvaluationResult = new EvaluationResultBase
                {
                    InvalidProperties        = arg.InvalidProperties,
                    InvalidValues            = arg.InvalidValues,
                    InvalidOperators         = arg.InvalidOperators,
                    InvalidVariables         = arg.InvalidVariables,
                    InvalidOrderByDirections = arg.InvalidOrderByDirections
                };
                error.Exceptions = exceptions;
                result.Error     = error;
            }
            else
            {
                result.Predicates    = predicates;
                result.OrderByClause = orderByClause;
            }

            return(result);
        }
コード例 #11
0
        public override IExplore Expolore(DelegateExpessionExplorer del)
        {
            List <TableClause> Tables2 = new List <TableClause>();

            Tables.ForEach(a =>
            {
                TableClause g2 = (TableClause)a.Expolore(del);
                if (g2 != null)
                {
                    Tables2.Add(g2);
                }
            });
            Tables.Replace(Tables2);
            List <ColumnClause> Columns2 = new List <ColumnClause>();

            Columns.ForEach(a =>
            {
                ColumnClause c = (ColumnClause)a.Expolore(del);
                if (c != null)
                {
                    Columns2.Add(c);
                }
            }
                            );
            Columns.Replace(Columns2);
            if (WhereExpr != null)
            {
                WhereExpr = (Expression)WhereExpr.Expolore(del);
            }
            if (GroupBys != null)
            {
                List <GroupByClause> GroupBys2 = new List <GroupByClause>();
                GroupBys.ForEach(a =>
                {
                    GroupByClause g2 = (GroupByClause)a.Expolore(del);
                    if (g2 != null)
                    {
                        GroupBys2.Add(g2);
                    }
                });
                GroupBys.Replace(GroupBys2);
            }
            if (Having != null)
            {
                Having = (Expression)Having.Expolore(del);
            }
            if (OrderBys != null)
            {
                List <OrderByClause> OrderBys2 = new List <OrderByClause>();
                OrderBys.ForEach(a =>
                {
                    OrderByClause g2 = (OrderByClause)a.Expolore(del);
                    if (g2 != null)
                    {
                        OrderBys2.Add(g2);
                    }
                });
                OrderBys.Replace(OrderBys2);
            }



            if (ExtSelects != null && ExtSelects.Count > 0)
            {
                var ExtSelects2 = new TokenList <ExtSelectClause>(this);
                foreach (var e in ExtSelects)
                {
                    var t = (ExtSelectClause)e.Expolore(del);
                    if (t != null)
                    {
                        ExtSelects2.Add(t);
                    }
                }
                ExtSelects = ExtSelects2;
            }
            return(base.Expolore(del));
        }
コード例 #12
0
 public void AppendOrderBy(OrderBy orderBy)
 {
     OrderBys.Add(orderBy);
 }
コード例 #13
0
 public void AppendOrderBy(IQueryableColumn column, OrderByDirection direction)
 {
     OrderBys.Add(new OrderBy(column, direction));
 }
コード例 #14
0
 protected override int GetHashCodeCore()
 {
     return(OrderBys.GetHashCode());
 }
コード例 #15
0
 protected override bool EqualsCore(NonEmptyOrderByCollection other)
 {
     return(OrderBys.SequenceEqual(other.OrderBys));
 }