Exemplo n.º 1
0
        /// <summary>
        /// 直接查询数据库视图
        /// </summary>
        /// <param name="table">表</param>
        /// <param name="lstScope">条件</param>
        /// <param name="vParams">字段列表</param>
        /// <param name="lstSort">排序类型</param>
        /// <param name="objPage">分页对象</param>
        /// <returns></returns>
        public DataSet SelectTable(BQLOtherTableHandle table, ScopeList lstScope)
        {
            List <BQLParamHandle> lstParams = GetParam(table, lstScope);

            List <BQLParamHandle> lstOrders = new List <BQLParamHandle>();
            BQLParamHandle        order     = null;

            foreach (Sort objSort in lstScope.OrderBy)
            {
                order = table[objSort.PropertyName];
                if (objSort.SortType == SortType.ASC)
                {
                    order = order.ASC;
                }
                else
                {
                    order = order.DESC;
                }
                lstOrders.Add(order);
            }

            BQLCondition where = BQLCondition.TrueValue;
            where = FillCondition(where, table, lstScope, null);

            BQLQuery bql = BQL.Select(lstParams.ToArray()).From(table).Where(where).OrderBy(lstOrders.ToArray());

            if (lstScope.HasPage)
            {
                using (BatchAction ba = _oper.StarBatchAction())
                {
                    return(QueryDataSet(bql, null, lstScope.PageContent, lstScope.UseCache));
                }
            }
            return(QueryDataSet(bql, null, lstScope.UseCache));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 查询表
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="lstScope">条件</param>
        /// <returns></returns>
        public E GetUnique <E>(ScopeList lstScope)
            where E : EntityBase, new()
        {
            Type eType = typeof(E);
            BQLEntityTableHandle table = _oper.DBInfo.FindTable(eType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(eType);
            }
            List <BQLParamHandle> lstParams = GetParam(table, lstScope);

            BQLCondition where = BQLCondition.TrueValue;
            where = FillCondition(where, table, lstScope);
            BQLQuery bql = BQL.Select(lstParams.ToArray())
                           .From(table)
                           .Where(where)
                           .OrderBy(GetSort(lstScope.OrderBy, table));

            return(GetUnique <E>(bql, lstScope.UseCache));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取范围表对应的BQL
        /// </summary>
        /// <param name="lstScope"></param>
        /// <param name="table"></param>
        /// <returns></returns>
        private BQLQuery GetSelectSql(ScopeList lstScope, BQLEntityTableHandle table)
        {
            List <BQLParamHandle> lstParams = GetParam(table, lstScope);

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

            if (lstScope.GroupBy.Count > 0)
            {
                bql = new KeyWordGroupByItem(lstScope.GroupBy, bql);
            }
            if (lstScope.OrderBy != null && lstScope.OrderBy.Count > 0)
            {
                bql = new KeyWordOrderByItem(GetSort(lstScope.OrderBy, table), bql);
            }

            return(bql);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 检测表结构
        /// </summary>
        /// <param name="lstSql">需要更新的SQL</param>
        /// <param name="dbInfo">数据库信息</param>
        /// <param name="table">要检测的表</param>
        private static void CheckTableStruct(List <string> lstSql, DBInfo dbInfo, KeyWordTableParamItem table)
        {
            string                    tableName = table.TableName;
            BQLQuery                  bql       = BQL.Select(BQL.ToTable(tableName)._).From(BQL.ToTable(tableName));
            SelectCondition           con       = BQLKeyWordManager.ToCondition(bql, dbInfo, null, true) as SelectCondition;
            string                    sql       = dbInfo.CurrentDbAdapter.GetTopSelectSql(con, 1);
            Dictionary <string, bool> dic       = new Dictionary <string, bool>();

            using (IDataReader reader = dbInfo.DefaultOperate.Query(sql, new Buffalo.DB.DbCommon.ParamList(), null))
            {
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    dic[reader.GetName(i).ToLower()] = true;
                }
            }

            StringBuilder sbSql  = new StringBuilder();
            string        desSQL = null;
            IDBAdapter    idb    = dbInfo.CurrentDbAdapter;

            foreach (EntityParam pInfo in table.Params)
            {
                if (!dic.ContainsKey(pInfo.ParamName.ToLower()))
                {
                    dbInfo.DBStructure.OnCheckEvent(pInfo, dbInfo, CheckEvent.TablenBeginCheck, lstSql);
                    bql = BQL.AlterTable(tableName).AddParam(pInfo);
                    AbsCondition acon = BQLKeyWordManager.ToCondition(bql, dbInfo, null, true);
                    lstSql.Add(acon.GetSql(false));
                    if (!string.IsNullOrEmpty(pInfo.Description))//添加注释
                    {
                        desSQL = idb.GetAddDescriptionSQL(table, pInfo, dbInfo);
                        if (!string.IsNullOrEmpty(desSQL))
                        {
                            lstSql.Add(desSQL);
                        }
                    }
                    dbInfo.DBStructure.OnCheckEvent(pInfo, dbInfo, CheckEvent.TableChecked, lstSql);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 查询是否存在符合条件的记录
        /// </summary>
        /// <param name="BQL">sql语句</param>
        /// <returns></returns>
        public bool ExistsRecord <E>(ScopeList lstScope)
            where E : EntityBase, new()
        {
            Type eType = typeof(E);
            BQLEntityTableHandle table = _oper.DBInfo.FindTable(eType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(eType);
            }
            List <BQLParamHandle> lstParams = new List <BQLParamHandle>();

            lstParams.Add(table[table.GetEntityInfo().PrimaryProperty[0].PropertyName]);

            BQLCondition where = BQLCondition.TrueValue;
            where = FillCondition(where, table, lstScope);
            BQLQuery bql = BQL.Select(lstParams.ToArray())
                           .From(table)
                           .Where(where)
                           .OrderBy(GetSort(lstScope.OrderBy, table));

            return(ExistsRecord <E>(bql, lstScope.UseCache));
        }
Exemplo 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);
        }