protected void AddExtendFilter(LiteQuery q)
 {
     foreach (ViewQueryEx ex in this.ViewQueryExs)
     {
         q.Filter = q.Filter.And(ex.GetFilter());
     }
 }
示例#2
0
        private void VisitQuery(LiteQuery q)
        {
            int?nullable;

            if (q.SkipNumber.HasValue && (((nullable = q.SkipNumber).GetValueOrDefault() > 0) && nullable.HasValue))
            {
                if (q.TakeNumber.HasValue && (((nullable = q.TakeNumber).GetValueOrDefault() > 0) && nullable.HasValue))
                {
                    this.VisitQuery_Skip_Take(q);
                }
                else
                {
                    this.VisitQuery_Skip_Null(q);
                }
            }
            else if (!q.SkipNumber.HasValue || (q.SkipNumber.Value <= 0))
            {
                if (q.TakeNumber.HasValue && (((nullable = q.TakeNumber).GetValueOrDefault() > 0) && nullable.HasValue))
                {
                    this.VisitQuery_Null_Take(q);
                }
                else
                {
                    this.ViewQuery_Null_Null(q);
                }
            }
        }
        public LiteQuery GetMMSubQuery(string innnerTableName, string leftFieldName, string rightFieldName, object rightValue)
        {
            string    tableAlias = string.Empty;
            LiteQuery query      = LiteQuery.New(innnerTableName, tableAlias);

            query.AddField(tableAlias, leftFieldName);
            query.Filter = FilterField.New(tableAlias, rightFieldName).Equal(rightValue);
            return(query);
        }
        protected LiteQuery GetRefSubQuery(string refTableName, string refKeyName, string refDisplayName, string foreignTableAlias, string foreignName)
        {
            string    tableAlias = string.Empty;
            LiteQuery query      = LiteQuery.New(refTableName, tableAlias);

            query.AddField(tableAlias, refDisplayName);
            query.Filter = FilterField.New(tableAlias, refKeyName).Equal(foreignTableAlias, foreignName);
            return(query);
        }
示例#5
0
        private void old_VisitQuery(LiteQuery q)
        {
            int?skipNumber;

            this.sb.Append(" WITH a AS ( SELECT main.*, ROWNUM AS ").Append(ROWNUM);
            this.sb.Append(" FROM (SELECT ");
            this.VisitSelectFields(q);
            this.sb.Append(" FROM ");
            this.VisitTableSource(q.TableSource);
            if ((q.Filter != null) && (q.Filter.GetRealNodeCount() > 0))
            {
                this.sb.Append(" WHERE ");
                this.VisitFilter(q.Filter);
            }
            if (q.GroupByList.Count > 0)
            {
                this.sb.Append(" GROUP BY ");
                this.VisitGroupByList(q);
            }
            if (q.Orders.Count > 0)
            {
                this.sb.Append(" ORDER BY ");
                this.VisitOrderList(q);
            }
            this.sb.Append(") main ) SELECT ");
            int num = -1;

            foreach (LiteField field in q.SelectFields)
            {
                num++;
                if (num > 0)
                {
                    this.sb.Append(",");
                }
                this.sb.Append("a.");
                this.sb.Append(field.FieldAlias);
                this.sb.Append(" ");
            }
            this.sb.Append(" FROM a WHERE a.").Append(ROWNUM).Append(" ");
            if (q.TakeNumber.HasValue && (q.TakeNumber.Value > 0))
            {
                this.sb.Append(" BETWEEN ");
                skipNumber = q.SkipNumber;
                this.sb.Append((int)((skipNumber.HasValue ? skipNumber.GetValueOrDefault() : 0) + 1));
                this.sb.Append(" AND ");
                skipNumber = q.SkipNumber;
                skipNumber = q.TakeNumber;
                this.sb.Append((int)((skipNumber.HasValue ? skipNumber.GetValueOrDefault() : 0) + (skipNumber.HasValue ? skipNumber.GetValueOrDefault() : 0)));
            }
            else
            {
                this.sb.Append(" > ");
                skipNumber = q.SkipNumber;
                this.sb.Append(skipNumber.HasValue ? skipNumber.GetValueOrDefault() : 0);
            }
        }
 protected void AddExtendOrder(LiteQuery q)
 {
     if (!(string.IsNullOrEmpty(this.OrderTableAlias) || string.IsNullOrEmpty(this.OrderFieldName)))
     {
         q.Orders.Clear();
         q.Orders.Add(new LiteOrderField(this.OrderTableAlias, this.OrderFieldName, this.OrderMethod));
     }
     if (q.Orders.Count == 0)
     {
         q.Orders.Add(new LiteOrderField("a", this.KeyName, King.Framework.LiteQueryDef.Internal.OrderMethod.DESC));
     }
 }
示例#7
0
        public void VisitSelectFields(LiteQuery q)
        {
            int num = -1;

            foreach (LiteField field in q.SelectFields)
            {
                num++;
                if (num > 0)
                {
                    this.sb.Append(",");
                }
                this.VisitSelectField(field);
            }
        }
示例#8
0
        private void VisitOrderList(LiteQuery q)
        {
            int num = -1;

            foreach (LiteOrderField field in q.Orders)
            {
                num++;
                if (num > 0)
                {
                    this.sb.Append(", ");
                }
                this.VisitOrderField(field);
            }
        }
示例#9
0
        private void VisitGroupByList(LiteQuery q)
        {
            int num = -1;

            foreach (LiteField field in q.GroupByList)
            {
                num++;
                if (num > 0)
                {
                    this.sb.Append(", ");
                }
                this.sb.Append("[");
                this.sb.Append(field.TableAlias);
                this.sb.Append("].[");
                this.sb.Append(field.FieldName);
                this.sb.Append("]");
            }
        }
示例#10
0
 private void VisitQuery_Null_Take(LiteQuery q)
 {
     this.sb.Append("SELECT ROWNUM as ").Append(ROWNUM);
     foreach (LiteField field in q.SelectFields)
     {
         this.sb.Append(", a.");
         this.sb.Append(field.FieldAlias);
     }
     this.sb.Append(" FROM (");
     this.ViewQuery_Null_Null(q);
     this.sb.Append(") a ");
     if (q.TakeNumber.HasValue && (q.TakeNumber.Value > 0))
     {
         this.sb.Append("WHERE ROWNUM <= ");
         int?skipNumber = q.SkipNumber;
         skipNumber = q.TakeNumber;
         this.sb.Append((int)((skipNumber.HasValue ? skipNumber.GetValueOrDefault() : 0) + (skipNumber.HasValue ? skipNumber.GetValueOrDefault() : 0)));
     }
 }
示例#11
0
        public override DataTable Query()
        {
            var q = LiteQuery.New("T_User", "a");

            q.SelectFields.Add(LiteField.NewEntityField("a", "User_ID"));
            q.SelectFields.Add(LiteField.NewEntityField("a", "User_Name"));
            q.SelectFields.Add(LiteField.NewEntityField("a", "User_Code"));
            q.SelectFields.Add(LiteField.NewEntityField("a", "Department_ID"));
            q.SelectFields.Add(LiteField.NewEntityField("a", "User_Mobile"));

            var subQ = GetRefSubQuery("T_Department", "Department_ID", "Department_Name", "a", "Department_ID");

            q.SelectFields.Add(LiteField.NewSubQueryField(subQ, "Department_ID_V"));

            q.Filter = LiteFilter.True();

            if (!string.IsNullOrEmpty(this.UserName))
            {
                var fUserName = FilterField.New("a", "User_Name").Contains(this.UserName);
                q.Filter = q.Filter.And(fUserName);
            }
            if (!string.IsNullOrEmpty(this.UserCode))
            {
                var fUserCode = FilterField.New("a", "User_Code").Contains(this.UserCode);
                q.Filter = q.Filter.And(fUserCode);
            }
            if (this.DepartmentId != null)
            {
                var fDeptId = FilterField.New("a", "Department_ID").Equal(this.DepartmentId.Value);
                q.Filter = q.Filter.And(fDeptId);
            }

            AddFilterForPrevilege(q);
            AddFilterForShared(q);

            q.SkipNumber = this.PageIndex * this.PageSize;
            q.TakeNumber = this.PageSize;

            return(this.DataHelper.ExecuteLiteQuery(q));
        }
示例#12
0
 private void ViewQuery_Null_Null(LiteQuery q)
 {
     this.sb.Append("SELECT ");
     this.VisitSelectFields(q);
     this.sb.Append(" FROM ");
     this.VisitTableSource(q.TableSource);
     if ((q.Filter != null) && (q.Filter.GetRealNodeCount() > 0))
     {
         this.sb.Append(" WHERE ");
         this.VisitFilter(q.Filter);
     }
     if (q.GroupByList.Count > 0)
     {
         this.sb.Append(" GROUP BY ");
         this.VisitGroupByList(q);
     }
     if (q.Orders.Count > 0)
     {
         this.sb.Append(" ORDER BY ");
         this.VisitOrderList(q);
     }
 }
示例#13
0
        private void VisitQuery_Skip_Take(LiteQuery q)
        {
            this.sb.Append("SELECT ");
            int num = -1;

            foreach (LiteField field in q.SelectFields)
            {
                num++;
                if (num > 0)
                {
                    this.sb.Append(",");
                }
                this.sb.Append(" a.");
                this.sb.Append(field.FieldAlias);
            }
            this.sb.Append(" FROM (");
            this.VisitQuery_Null_Take(q);
            this.sb.Append(") a WHERE a.").Append(ROWNUM).Append(" > ");
            int?skipNumber = q.SkipNumber;

            this.sb.Append(skipNumber.HasValue ? skipNumber.GetValueOrDefault() : 0);
        }
示例#14
0
 protected void AddExtendFilterAndOrder(LiteQuery q)
 {
     this.AddExtendFilter(q);
     this.AddExtendOrder(q);
 }
 internal static ILiteVisitor GetLiteVisitor(DatabaseTypeEnum dbType, LiteQuery q)
 {
     return(liteVisitorDict[dbType](q));
 }
示例#16
0
 private void VisitSubQuery(LiteQuery q)
 {
     this.VisitQuery(q);
 }
示例#17
0
        private void VisitQuery(LiteQuery q)
        {
            int? takeNumber;
            bool flag = this.NeedRowNumber(q);

            if (flag)
            {
                this.sb.Append(" WITH a AS ( SELECT ");
                this.sb.Append(" ROW_NUMBER() ");
                if (q.Orders.Count <= 0)
                {
                    throw new ApplicationException("必须提供排序");
                }
                this.sb.Append(" OVER ( ORDER BY ");
                this.VisitOrderList(q);
                this.sb.Append(") ");
                this.sb.Append(" AS __row_number__ ,");
            }
            else
            {
                this.sb.Append(" SELECT ");
                if (q.TakeNumber.HasValue)
                {
                    this.sb.Append(" TOP ");
                    takeNumber = q.TakeNumber;
                    this.sb.Append(takeNumber.HasValue ? takeNumber.GetValueOrDefault() : 0);
                    this.sb.Append(" ");
                }
            }
            if (q.Distinct)
            {
            }
            this.VisitSelectFields(q);
            this.sb.Append(" FROM ");
            this.VisitTableSource(q.TableSource);
            if ((q.Filter != null) && (q.Filter.GetRealNodeCount() > 0))
            {
                this.sb.Append(" WHERE ");
                this.VisitFilter(q.Filter);
            }
            if (q.GroupByList.Count > 0)
            {
                this.sb.Append(" GROUP BY ");
                this.VisitGroupByList(q);
            }
            if (flag)
            {
                this.sb.Append(" ) select ");
                int num = -1;
                foreach (LiteField field in q.SelectFields)
                {
                    num++;
                    if (num > 0)
                    {
                        this.sb.Append(",");
                    }
                    this.sb.Append("a.[");
                    this.sb.Append(field.FieldAlias);
                    this.sb.Append("]");
                }
                this.sb.Append(" from a WHERE __row_number__  ");
                if (q.TakeNumber.HasValue && (q.TakeNumber.Value > 0))
                {
                    this.sb.Append(" BETWEEN ");
                    takeNumber = q.SkipNumber;
                    this.sb.Append((int)((takeNumber.HasValue ? takeNumber.GetValueOrDefault() : 0) + 1));
                    this.sb.Append(" AND ");
                    takeNumber = q.SkipNumber;
                    takeNumber = q.TakeNumber;
                    this.sb.Append((int)((takeNumber.HasValue ? takeNumber.GetValueOrDefault() : 0) + (takeNumber.HasValue ? takeNumber.GetValueOrDefault() : 0)));
                }
                else
                {
                    this.sb.Append(" > ");
                    takeNumber = q.SkipNumber;
                    this.sb.Append(takeNumber.HasValue ? takeNumber.GetValueOrDefault() : 0);
                }
            }
            else if (q.Orders.Count > 0)
            {
                this.sb.Append(" ORDER BY ");
                this.VisitOrderList(q);
            }
        }
示例#18
0
        public DataTable ExecuteLiteQuery(LiteQuery q)
        {
            string sql = DatabaseFactory.GetLiteVisitor(this._databaseType, q).Visit();

            return(this.ExecuteDataTable(sql, new DbParameter[0]));
        }
示例#19
0
 public OracleVisitor(LiteQuery query)
 {
     this._query = query;
 }
示例#20
0
 protected void AddFilterForPrevilege(LiteQuery q)
 {
 }
示例#21
0
 public SqlVisitor(LiteQuery query)
 {
     this._query = query;
 }
示例#22
0
 protected void AddFilterForShared(LiteQuery q)
 {
 }
示例#23
0
        private bool NeedRowNumber(LiteQuery q)
        {
            int?skipNumber = q.SkipNumber;

            return((skipNumber.HasValue ? skipNumber.GetValueOrDefault() : 0) > 0);
        }