示例#1
0
        public List <T> Query <T>(QueryPara parameter)
        {
            if (parameter.TargetTime1 > parameter.TargetTime2)
            {
                return(new List <T>());
            }

            var context = GetDivisionContext(parameter);

            return(DBProvider.GetList <T>(context));
        }
示例#2
0
        public DataTable Query(QueryPara parameter)
        {
            if (parameter.TargetTime1 > parameter.TargetTime2)
            {
                return(new DataTable());
            }

            var context = GetDivisionContext(parameter);

            return(DBProvider.GetTable(context));
        }
示例#3
0
        private DivisionContext GetDivisionContext(QueryPara parameter)
        {
            DivisionContext context = new DivisionContext();

            context.IDbSchema     = IDbSchema;
            context.Database      = this;
            context.ITableSchemas = new List <ITableSchema>();
            context.QueryPara     = parameter;

            //提取表名
            Regex regex  = new Regex(@"『(?<tableName>.+?)』", RegexOptions.Multiline);
            var   matchs = regex.Matches(parameter.Sql);

            foreach (Match match in matchs)
            {
                string tableName = match.Groups["tableName"].Value;
                var    table     = Tables[tableName];

                if (!context.ITableSchemas.Contains(table.ITableSchema))
                {
                    context.ITableSchemas.Add(table.ITableSchema);
                }
            }

            //找到粒度最小的
            var      divisionType = context.ITableSchemas.Count > 0 ? context.ITableSchemas.Max(o => o.Table.DivisionType) : DivisionType;
            DateTime tempTime1    = parameter.TargetTime1;
            DateTime tempTime2    = parameter.TargetTime2;

            divisionType.SetTargetTime(ref tempTime1, ref tempTime2);

            var tempQueryItems = new List <QueryItem>();

            while (true)
            {
                QueryItem queryItem = new QueryItem();
                queryItem.ExecSql = parameter.Sql;
                var suffix = "";
                queryItem.DatabaseName   = GetRealName(tempTime1, ref suffix);
                queryItem.DatabaseSuffix = suffix;

                //需要替换的表
                foreach (var tableSchema in context.ITableSchemas)
                {
                    suffix = "";
                    string tableName = tableSchema.Table.GetRealName(tempTime1, ref suffix);
                    var    tablePack = new TablePack
                    {
                        DatabaseName   = queryItem.DatabaseName,
                        DatabaseSuffix = queryItem.DatabaseSuffix,
                        TableName      = tableName,
                        TableSuffix    = suffix,
                        queryItem      = queryItem
                    };
                    queryItem.TableNames.Add(tableSchema, tablePack);
                    queryItem.ExecSql = queryItem.ExecSql.Replace($"『{tableSchema.Table.Name}』", $" {tableName} ");
                }
                queryItem.TargetTime = tempTime1;

                tempQueryItems.Add(queryItem);

                divisionType.PlusTargetTime(ref tempTime1);

                if (tempTime1 > tempTime2)
                {
                    break;
                }
            }

            context.QueryItems = tempQueryItems.GroupBy(o => o.DatabaseName).ToDictionary(g => g.Key, g => g.ToList());

            return(context);
        }
示例#4
0
        public int Update <T>(QueryPara parameter, T t, Expression <Func <T, object> > whereProperties, params Expression <Func <T, object> >[] ignoreProperties)
        {
            var context = GetDivisionContext(parameter);

            return(DBProvider.Update(context, t, whereProperties, ignoreProperties));
        }
示例#5
0
        public int Insert <T>(QueryPara parameter, T t, params Expression <Func <T, object> >[] ignoreProperties)
        {
            var context = GetDivisionContext(parameter);

            return(DBProvider.Insert(context, t, ignoreProperties));
        }
示例#6
0
        public int Execute(QueryPara parameter)
        {
            var context = GetDivisionContext(parameter);

            return(DBProvider.Execute(context));
        }