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)); }
public DataTable Query(QueryPara parameter) { if (parameter.TargetTime1 > parameter.TargetTime2) { return(new DataTable()); } var context = GetDivisionContext(parameter); return(DBProvider.GetTable(context)); }
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); }
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)); }
public int Insert <T>(QueryPara parameter, T t, params Expression <Func <T, object> >[] ignoreProperties) { var context = GetDivisionContext(parameter); return(DBProvider.Insert(context, t, ignoreProperties)); }
public int Execute(QueryPara parameter) { var context = GetDivisionContext(parameter); return(DBProvider.Execute(context)); }