Ejemplo n.º 1
0
        /// <summary>
        /// 输出关键字转换后的SQL语句
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static AbsCondition ToCondition(BQLQuery item, DBInfo db, TableAliasNameManager aliasManager, bool isPutPropertyName)
        {
            KeyWordInfomation info = CreateKeywordInfo(db);

            info.AliasManager            = aliasManager;
            info.Infos.IsPutPropertyName = isPutPropertyName;
            return(DoConver(info, item));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// from关键字
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        internal override void Tran(KeyWordInfomation info)
        {
            StringBuilder ret = new StringBuilder();


            if (info.AliasManager == null)
            {
                for (int i = 0; i < _tables.Length; i++)
                {
                    BQLTableHandle table     = _tables[i];
                    string         tableName = table.DisplayValue(info);
                    ret.Append(tableName);
                    if (i < _tables.Length - 1)
                    {
                        ret.Append(",");
                    }
                }
                info.Condition.Tables.Append(ret.ToString());
            }
            else
            {
                for (int i = 0; i < _tables.Length; i++)
                {
                    BQLTableHandle table = _tables[i];

                    BQLAliasHandle ahandle = info.AliasManager.GetPrimaryAliasHandle(table);
                    if (!Buffalo.Kernel.CommonMethods.IsNull(ahandle))
                    {
                        _tables[i] = ahandle;
                    }
                }


                KeyWordFromItem       from    = info.AliasManager.ToInnerTable(this, info);
                TableAliasNameManager manager = info.AliasManager;
                info.AliasManager = null;
                Stack <KeyWordFromItem> stkFrom = new Stack <KeyWordFromItem>();
                while (from != null)
                {
                    stkFrom.Push(from);
                    from = from.Previous as KeyWordFromItem;
                }
                while (stkFrom.Count > 0)
                {
                    from = stkFrom.Pop();
                    from.Tran(info);
                }
                info.AliasManager = manager;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 转成条件信息
        /// </summary>
        /// <param name="BQL"></param>
        /// <param name="db"></param>
        /// <param name="aliasManager"></param>
        /// <returns></returns>
        private AbsCondition ToCondition(BQLQuery BQL, IEnumerable <BQLEntityTableHandle> outPutTables,
                                         bool isPutPropertyName, Type entityType)
        {
            TableAliasNameManager aliasManager = null;

            if (entityType != null)
            {
                aliasManager = new TableAliasNameManager(new BQLEntityTableHandle(EntityInfoManager.GetEntityHandle(entityType)));
            }
            if (outPutTables != null)
            {
                FillOutPutTables(outPutTables, aliasManager);
            }
            AbsCondition con = BQLKeyWordManager.ToCondition(BQL, _oper.DBInfo, aliasManager, isPutPropertyName);

            return(con);
        }
Ejemplo n.º 4
0
        private List <E> LoadFromReader <E>(TableAliasNameManager aliasManager, IDataReader reader)
            where E : EntityBase
        {
            List <E> lst = new List <E>();

            if (reader != null && !reader.IsClosed)
            {
                aliasManager.InitMapping(reader);
                while (reader.Read())
                {
                    object value = aliasManager.LoadFromReader(reader);
                    if (value != null)
                    {
                        E obj = value as E;
                        //obj.SetBaseList(lst);
                        lst.Add(obj);
                    }
                }
            }
            return(lst);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取第一条记录
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="BQL"></param>
        /// <returns></returns>
        public E GetUnique <E>(BQLQuery BQL, bool useCache)
            where E : EntityBase, new()
        {
            Type tableType = typeof(E);
            TableAliasNameManager aliasManager = new TableAliasNameManager(new BQLEntityTableHandle(EntityInfoManager.GetEntityHandle(tableType)));


            AbsCondition con = BQLKeyWordManager.ToCondition(BQL, _oper.DBInfo, aliasManager, true);
            Dictionary <string, bool> cacheTables = null;

            if (useCache)
            {
                cacheTables = con.CacheTables;
            }
            string      sql    = con.DBinfo.CurrentDbAdapter.GetTopSelectSql(con as SelectCondition, 1);
            E           ret    = default(E);
            IDataReader reader = _oper.Query(sql, con.DbParamList, cacheTables);

            try
            {
                con.Oper = _oper;
                bool hasValue = true;
                aliasManager.InitMapping(reader);
                if (reader.Read())
                {
                    ret = aliasManager.LoadFromReader(reader) as E;
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(ret);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 查询总条数
        /// </summary>
        /// <param name="lstScope"></param>
        /// <returns></returns>
        public virtual long SelectCount <E>(ScopeList lstScope)
        {
            long ret   = 0;
            Type eType = typeof(E);
            TableAliasNameManager aliasManager = new TableAliasNameManager(new BQLEntityTableHandle(EntityInfoManager.GetEntityHandle(typeof(E))));
            BQLEntityTableHandle  table        = _oper.DBInfo.FindTable(eType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(eType);
            }

            BQLCondition where = BQLCondition.TrueValue;
            where = FillCondition(where, table, lstScope);
            BQLQuery bql = BQL.Select(BQL.Count())
                           .From(table)
                           .Where(where);

            //if(lstScope.GroupBy

            AbsCondition con = BQLKeyWordManager.ToCondition(bql, _oper.DBInfo, aliasManager, true);
            Dictionary <string, bool> cacheTables = null;

            if (lstScope.UseCache)
            {
                cacheTables = con.CacheTables;
            }
            using (IDataReader reader = _oper.Query(con.GetSql(lstScope.UseCache), con.DbParamList, cacheTables))
            {
                if (reader.Read())
                {
                    ret = Convert.ToInt64(reader[0]);
                }
            }
            return(ret);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 填充要输出的表
 /// </summary>
 /// <param name="outPutTables"></param>
 /// <param name="aliasManager"></param>
 private void FillOutPutTables(IEnumerable <BQLEntityTableHandle> outPutTables, TableAliasNameManager aliasManager)
 {
     if (outPutTables == null)
     {
         return;
     }
     foreach (BQLEntityTableHandle table in outPutTables)
     {
         aliasManager.AddChildTable(table);
     }
 }