static TableFragment ExtractTransitionTable(ConfigTable table, CharSet[] charSets, int[] charClassMap, Dictionary <Graph.State, int> stateMap, Statistics statistics) { var fragments = new List <TableFragment>(); foreach (var fromState in table.Graph.States) { int[] transitionsList = null; for (var i = 0; i < charSets.Length; i++) { var toState = NextState(fromState, charSets[charClassMap[i]]); if (toState != null) { if (transitionsList == null) { transitionsList = new int[charSets.Length]; } transitionsList[i] = stateMap[toState] + 1; } } if (transitionsList != null) { fragments.Add(new TableFragment(transitionsList, stateMap[fromState])); } else { statistics.StatesTerminal++; } } return(TableFragment.Combine(fragments)); }
public ParseTableRow(TableFragment fragment, bool hasReduction, bool hasShift) { Fragment = fragment; ShortCircuitReduction = 0; HasReduction = hasReduction; HasShift = hasShift; }
public TypeProxy(TableFragment fragment) { _elements = new TypeProxyElement[fragment.Count]; var empty = Array.Empty <int>(); var states = new Dictionary <int, List <int> >(); for (var i = 0; i < fragment._states.Length; i++) { var offset = fragment._offsets[i]; if (!states.TryGetValue(offset, out var list)) { list = new List <int>(); states.Add(offset, list); } list.Add(fragment._states[i]); } for (var i = 0; i < fragment.Count; i++) { states.TryGetValue(i, out var list); _elements[i] = new TypeProxyElement(fragment[i], list == null ? empty : list.ToArray()); } Skip = fragment.Skip; }
/// <summary> /// 根据指定类型<see cref="DbDataSetExpression"/>表达式创建数据源语句片段。 /// </summary> /// <param name="context">生成上下文。</param> /// <param name="expression">指定表达式。</param> /// <returns>创建结果。</returns> protected virtual ISourceFragment CreateSourceForDataSet(GenerateContext context, DbExpression expression) { var content = (DbDataSetExpression)expression; var metadata = context.Metadata.Table(content.Item.ClrType); SourceFragment table = null; if (metadata.InheritSets.Length > 0) { if (content.Name != null) { throw new NotSupportedException(Res.NotSupportedInheritSetUsingDbName); } table = new InheritFragment(context, metadata); } else { table = new TableFragment(context, content); } context.RegisterSource(content.Item, table); context.RegisterSource(content, table); if (IsSelectFragment(content)) { return(InitialSelectFragment(new SelectFragment(context, table), content)); } if (table is InheritFragment inherit) { inherit.Initialize(); } return(table); }
internal static InsertValueFragment InsertUnit(this ContentBase data, CommitIdentityUnit unit, DbName name = null) { var context = data.GenerateContext; var target = new TableFragment(context, unit.Table, name); var insert = new InsertValueFragment(context, target, data.CommitObject, data.Items); data.CommitObject.Parent = insert; unit.Members.ForEach(member => SetCommitMember(insert, member)); return(insert); }
public void CopyTo() { var fragment = new TableFragment(new int[] { 1, 2, 3, 4 }, 0); var array = new int[6]; fragment.CopyTo(array, 1); Assert.That(array, Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 0 })); }
/// <summary> /// 使用临时表形式,生成插入单个数据对象语句,对象的主键是标识列, /// 要求数据库拥有<see cref="EDbCapable.TemporaryTable"/> /// 和<see cref="EDbCapable.ModifyJoin"/>两个特性。 /// </summary> /// <param name="context">生成上下文。</param> /// <returns>语句片段。</returns> protected virtual SqlFragment GenerateForInsertIdentityTempTable(GenerateContext context) { var data = (GenerateDataForInsert)context.Data; var mainunit = (CommitIdentityUnit)data.MainUnit; var members = data.GetTables().SelectMany(a => a.Members).ToList(); var rowindex = new ColumnMetadata(data.Table, SupportMembers.DbMembers.CustomRowIndex, members.Select(a => a.Name).Unique("RowIndex")); members.Add(rowindex); var createtable = new CreateTempTableFragment(context, members); var temptable = createtable.Table; var insert = new InsertValueFragment(context, temptable, data.CommitObject, data.Items); data.CommitObject.Parent = insert; foreach (var unit in data.GetUnits()) { unit.Members.ForEach(member => GenerateForInsertMembers(insert, member)); } insert.SetValue(mainunit.Identity.Metadata, new SimpleFragment(context, "0")); var rowindexfragment = new RowIndexFragment(context); insert.SetValue(rowindex, rowindexfragment); TableFragment whileTarget = null; BlockFragment block = null; if (context.Feature.HasCapable(EDbCapable.ExternalCompoundStatement)) { var index = new CreateVariableFragment(context, typeof(int)); var whilefragment = GenerateForInsertIdentityMultipleWhile(context, mainunit, index, rowindex, createtable.Table, rowindexfragment, out whileTarget); block = new BlockFragment(context, index, createtable, insert, context.Assign(index.Name, context.StatementString("1")), whilefragment); } else { var repeatfragment = GenerateForInsertIdentityMultipleRepeat(context, mainunit, rowindex, createtable.Table, rowindexfragment, data, out whileTarget); block = new BlockFragment(context, createtable, insert, repeatfragment); } if (data.SubUnits != null) { foreach (var unit in data.SubUnits) { block.Add(context.Insert(createtable.Table, unit)); } } GenerateForInsertReturnStatement(context, block, whileTarget, createtable.Table); return(block); }
/// <summary> /// 生成添加若干复合关系对象语句。 /// </summary> /// <param name="context">生成上下文。</param> /// <returns>语句片段。</returns> protected virtual SqlFragment GenerateForRelationInsert(GenerateContext context) { var data = (RelationContent)context.Data; var metadata = (CompositeNavigateMetadata)data.Items.Navigate; var target = new TableFragment(context, data.Table); var insert = new InsertValueFragment(context, target, data.CommitObject, data.Items); metadata.Pairs.ForEach(pair => insert.SetValue(pair.ForeignKey, data.CommitObject.GetMember(pair.PrincipalKey))); metadata.CompositePairs.ForEach(pair => insert.SetValue(pair.ForeignKey, data.CommitObject.GetMember(pair.PrincipalKey))); return(insert); }
public void CheckStatement(int row, List <UITable> expectedTransactions) { //Удаляем из ожидаемой таблицы строку с Датой., т.к. проверяется ниже expectedTransactions.RemoveAll(it => it.Column1.Equals("Дата")); //Клик по номеру операции сверху. _context.Grid.FindElement(statementListLocator).FindElements(By.CssSelector("ul"))[row].Click(); //Проверка ожидаемой/фактической таблиц TableFragment.CheckTablesWithOrder(_context.Grid, statementListLocator, ReplaceTable(expectedTransactions, _context.Rate, _context.Amount, _context.PurseTransactionId, _context.InvoiceId, _context.ExternalTransactionId, null, _context.Email ?? _context.PhoneNumber), row); CommonComponentSteps.MakeScreenshot(); }
internal static InsertFragment InsertTemptable(this ContentBase data, TemporaryTableFragment temptable, CommitKeyUnit unit, DbName name = null) { var members = unit.Keys.Concat(unit.Members).Select(a => a.Metadata); var context = data.GenerateContext; var table = new TableFragment(context, unit.Table, name); var select = new SelectFragment(context, temptable); var current = new InsertFragment(context, table, select); foreach (var member in members) { select.CreateMember(null, temptable.GetMember(member)); current.CreateMember(null, member); } return(current); }
/// <summary> /// 创建继承表语句。 /// </summary> /// <param name="context">生成上下文。</param> /// <param name="metadata">数据表元数据。</param> public InheritFragment(GenerateContext context, TableMetadata metadata) : base(context) { Metadata = metadata; var inheritSets = Metadata.InheritSets; Tables = new TableFragment[inheritSets.Length + 1]; var index = 0; for (; index < inheritSets.Length; index++) { Tables[index] = new TableFragment(context, inheritSets[index]); } Tables[index] = new TableFragment(context, Metadata); }
/// <summary> /// 生成删除单个复合关系对象语句。 /// </summary> /// <param name="context">生成上下文。</param> /// <returns>语句片段。</returns> protected virtual SqlFragment GenerateForRelationDelete(GenerateContext context) { var data = (RelationContent)context.Data; var metadata = (CompositeNavigateMetadata)data.Items.Navigate; var target = new TableFragment(context, data.Table); var source = data.CommitObject; var delete = new DeleteFragment(context, target); delete.Where = metadata.Pairs.Concat(metadata.CompositePairs).Select( pair => new BinaryFragment(context, Expressions.EBinaryKind.Equal) { Left = target.GetMember(pair.ForeignKey), Right = source.GetMember(pair.PrincipalKey) }).Merge(); return(delete); }
public void Skip_NoExcess() { var fragment1 = new TableFragment(new int[] { 1, 1, 2, 2 }, 0); var fragment2 = new TableFragment(new int[] { 2 }, 1, 2); var combined = TableFragment.Combine(new TableFragment[] { fragment1, fragment2, }); Assert.That(combined.Skip, Is.EqualTo(0)); Assert.That(combined, Is.EquivalentTo(new int[] { 1, 1, 2, 2 })); Assert.That(combined.GetOffset(0), Is.EqualTo(0)); Assert.That(combined.GetOffset(1), Is.EqualTo(1)); }
public void Skip_WithExcess() { var fragment1 = new TableFragment(new int[] { 1, 1, 2, 2 }, 0); var fragment2 = new TableFragment(new int[] { 2, 2, 3 }, 1, 0); var fragment3 = new TableFragment(new int[] { 3 }, 2, 5); var combined = TableFragment.Combine(new TableFragment[] { fragment1, fragment2, fragment3, }); Assert.That(combined.Skip, Is.EqualTo(1)); Assert.That(combined, Is.EquivalentTo(new int[] { 1, 1, 2, 2, 3 })); Assert.That(combined.GetOffset(0), Is.EqualTo(0)); Assert.That(combined.GetOffset(1), Is.EqualTo(2)); Assert.That(combined.GetOffset(2), Is.EqualTo(-1)); }
/// <summary> /// 表达式生成删除语句。 /// </summary> /// <param name="context">生成上下文。</param> /// <param name="content">生成表达式。</param> /// <returns>语句片段。</returns> protected virtual SqlFragment GenerateForDeleteStatement(GenerateContext context, DbExpression content) { var data = (StatementContent)context.Data; var item = data.ItemEpxression; var source = CreateSource(context, content) as QueryBaseFragment; var table = data.Table; if (table.InheritSets.Length == 0) { var target = (TableFragment)GetSource(context, item); target.Name = context.ConvertName(data.TargetName); var delete = new DeleteFragment(context, target) { Where = source.Where, Take = source.Take }; delete.AddSource(source.Sources.Where(a => a != target)); return(delete); } else { var createtable = new CreateTempTableFragment(context, table.Keys); var insert = new InsertFragment(context, createtable.Table, source); insert.Members.AddRange(createtable.Table.Members); foreach (var key in table.Keys) { RetrievalMember(context, source, new DbMemberExpression(key.Member, item), null, false); } var block = new BlockFragment(context, createtable, insert); foreach (var subtable in table.InheritSets.Concat(new TableMetadata[] { table }).Reverse()) { var current = new TableFragment(context, subtable); var delete = new DeleteFragment(context, current); var temptable = new TemporaryTableFragment(context, table.Keys, createtable.Table.Name); current.Join(temptable, table.Keys); delete.AddSource(temptable); block.Add(delete); } return(block); } }
/// <summary> /// 生成插入若干数据对象语句。 /// </summary> /// <param name="context">生成上下文。</param> /// <returns>语句片段。</returns> protected virtual SqlFragment GenerateForInsertSimple(GenerateContext context) { var data = (GenerateDataForInsert)context.Data; var name = data.TargetName; var block = new BlockFragment(context); var mainunit = (CommitKeyUnit)data.MainUnit; InsertValueFragment mainInsert = null; foreach (var unit in data.GetUnits().OfType <CommitKeyUnit>()) { var target = new TableFragment(context, unit.Table, name); var insert = new InsertValueFragment(context, target, data.CommitObject, data.Items); data.CommitObject.Parent = insert; unit.Keys.Concat(unit.Members).ForEach(member => GenerateForInsertMembers(insert, member)); block.Add(insert); mainInsert = insert; } GenerateForInsertReturnStatement(context, block, mainInsert.Target, null); return(block); }
/// <summary> /// 使用临时表形式,生成删除多个复合关系的语句, /// 要求数据库拥有<see cref="EDbCapable.TemporaryTable"/> /// 和<see cref="EDbCapable.ModifyJoin"/>两个特性。 /// </summary> /// <param name="context">生成上下文。</param> /// <returns>语句片段。</returns> protected virtual SqlFragment GenerateForRelationDeleteTempTable(GenerateContext context) { var data = (RelationContent)context.Data; var composite = (CompositeNavigateMetadata)data.Items.Navigate; var createtemptable = new CreateTempTableFragment(context, composite.Pairs.Select(a => a.ForeignKey).Concat(composite.CompositePairs.Select(a => a.ForeignKey))); var insert = new InsertValueFragment(context, createtemptable.Table, data.CommitObject, data.Items); composite.Pairs.ForEach(pair => insert.SetValue(pair.ForeignKey, data.CommitObject.GetMember(pair.PrincipalKey))); composite.CompositePairs.ForEach(pair => insert.SetValue(pair.ForeignKey, data.CommitObject.GetMember(pair.PrincipalKey))); var temptable = createtemptable.Table; var target = new TableFragment(context, data.Table); var delete = new DeleteFragment(context, target); delete.AddSource(temptable); target.Join(temptable, composite.Pairs.Select(a => a.ForeignKey).Concat(composite.CompositePairs.Select(a => a.ForeignKey))); return(new BlockFragment(context, createtemptable, insert, delete)); }
public static InsertFragment Insert(this GenerateContext context, ISourceFragment source, TableMetadata target , IEnumerable <ColumnMetadata> members) { DbName name = null; if (context.Data is ContentBase data) { name = data.TargetName; } var table = new TableFragment(context, target, name); var select = new SelectFragment(context, source); var current = new InsertFragment(context, table, select); foreach (var member in members) { select.CreateMember(null, source.GetMember(member)); current.CreateMember(null, member); } return(current); }
/// <inheritdoc/> protected override SqlFragment GenerateForRelation(GenerateContext context, DbExpression content) { var data = (RelationContent)context.Data; if (data.Items.Count > 1) { var metadata = data.Items.Navigate; if (data.IsAddRelation && !metadata.IsComposite) { var columns = data.Source.Keys.Concat(metadata.Pairs.Select(a => a.ForeignKey)); var values = new ValuesFragment(context, data.CommitObject, data.Items); data.Source.Keys.ForEach(key => values.SetValue(key)); if (data.IsAddRelation) { metadata.Pairs.ForEach( pair => values.SetValue(pair.ForeignKey, data.CommitObject.GetMember(pair.PrincipalKey))); } var update = new UpdateFragment(context, data.Table); update.AddSource(update.Target, values); foreach (var pair in metadata.Pairs) { update.SetValue(pair.ForeignKey, values.GetMember(pair.ForeignKey)); } update.Target.Join(values, data.Table.Keys); return(update); } else if (!data.IsAddRelation && metadata.IsComposite) { var composite = (CompositeNavigateMetadata)data.Items.Navigate; var values = new ValuesFragment(context, data.CommitObject, data.Items); composite.Pairs.ForEach(pair => values.SetValue(pair.ForeignKey, data.CommitObject.GetMember(pair.PrincipalKey))); composite.CompositePairs.ForEach(pair => values.SetValue(pair.ForeignKey, data.CommitObject.GetMember(pair.PrincipalKey))); var target = new TableFragment(context, data.Table); var delete = new DeleteFragment(context, target); delete.AddSource(values); target.Join(values, composite.Pairs.Select(a => a.ForeignKey).Concat(composite.CompositePairs.Select(a => a.ForeignKey))); return(delete); } } return(base.GenerateForRelation(context, content)); }
/// <summary> /// 生成用于插入的语句片段。 /// </summary> /// <param name="context">生成上下文。</param> /// <param name="content">插入表达式。</param> /// <returns>生成结果。</returns> protected virtual SqlFragment GenerateForInsertStatement(GenerateContext context, DbExpression content) { var data = (StatementContent)context.Data; var newitem = (DbNewExpression)data.ItemEpxression; var source = CreateSource(context, content) as QueryBaseFragment; var metadata = data.Table; if (metadata.InheritSets.Length == 0) { var target = new TableFragment(context, metadata, data.TargetName); var insert = new InsertFragment(context, target, source); GenerateForInsertStatementMembers(context, newitem, source, insert, member => metadata.Members[member]); return(insert); } else { var allsource = metadata.InheritSets.Concat(new TableMetadata[] { metadata }); var allmembers = allsource.SelectMany(a => a.Members).ToDictionary(a => a.Member, a => a); var createtable = new CreateTempTableFragment(context, newitem.Members.Keys.OfType <PropertyInfo>().Select(a => allmembers[a])); var insert = new InsertFragment(context, createtable.Table, source); GenerateForInsertStatementMembers(context, newitem, source, insert, member => allmembers[member]); var block = new BlockFragment(context, createtable, insert); var query = from a in newitem.Members.Keys.OfType <PropertyInfo>().Select(m => allmembers[m]) group a by a.Table into g select new { g.Key, Members = g }; var prefixMembers = query.First().Members.Where(a => a.IsKey); foreach (var g in query) { IEnumerable <ColumnMetadata> currentMembers = g.Members; if (g.Key.InheritSets.Length > 0) { currentMembers = prefixMembers.Concat(g.Members); } var current = new TemporaryTableFragment(context, currentMembers, createtable.Table.Name); block.Add(context.Insert(current, g.Key, currentMembers)); } return(block); } }
public void Combine() { var fragment1 = new TableFragment(new int[] { 1, 2, 3, -1 }, 0); var fragment2 = new TableFragment(new int[] { 1, 2, 3, -1 }, 1); var fragment3 = new TableFragment(new int[] { -1, -1, 2, -1 }, 2); var fragment4 = new TableFragment(new int[] { -1, 1, -1, -1 }, 3); var combined = TableFragment.Combine(new TableFragment[] { fragment1, fragment2, fragment3, fragment4, }); Assert.That(combined.Skip, Is.EqualTo(0)); Assert.That(combined, Is.EquivalentTo(new int[] { 1, 2, 3, -1, 1, -1, -1, 2, -1 })); Assert.That(combined.GetOffset(0), Is.EqualTo(0)); Assert.That(combined.GetOffset(1), Is.EqualTo(0)); Assert.That(combined.GetOffset(2), Is.EqualTo(5)); Assert.That(combined.GetOffset(3), Is.EqualTo(3)); Assert.That(combined.GetOffset(4), Is.EqualTo(null)); }
private WhileFragment GenerateForInsertIdentityMultipleWhile(GenerateContext context, CommitIdentityUnit mainunit, CreateVariableFragment index, ColumnMetadata rowindex, TemporaryTableFragment temporaryTable, RowIndexFragment rowindexfragment, out TableFragment whileTarget) { var whilefragment = new WhileFragment(context, context.LessThan(index.Name, rowindexfragment)); var block = whilefragment.Block; var whileInsert = context.Insert(temporaryTable, mainunit.Table, mainunit.Members.Where(a => a.ValueType != ECommitValueType.Database).Select(a => a.Metadata)); var whileSelect = (QueryBaseFragment)whileInsert.Query; whileSelect.Where = context.Equal(temporaryTable.GetMember(rowindex), index.Name); block.Add(whileInsert); var whileUpdate = new UpdateFragment(context, temporaryTable); var getidentity = whileUpdate.CreateExpression( context.Translate(Expression.Call(null, SupportMembers.DbFunctions.GetIdentity))); whileUpdate.SetValue(mainunit.Identity.Metadata, getidentity); whileUpdate.Where = context.Equal(temporaryTable.GetMember(rowindex), index.Name); block.Add(whileUpdate); block.Add(context.Assign(index.Name, context.Add(index.Name, context.StatementString("1")))); whileTarget = (TableFragment)whileInsert.Target; return(whilefragment); }
/// <summary> /// 表达式生成更新语句。 /// </summary> /// <param name="context">生成上下文。</param> /// <param name="content">生成表达式。</param> /// <returns>语句片段。</returns> protected virtual SqlFragment GenerateForUpdateStatement(GenerateContext context, DbExpression content) { SourceFragment GetRootSource(ISourceFragment query) { if (query is SelectFragment select) { return(GetRootSource(select.Sources.FirstOrDefault())); } else if (query is TableFragment || query is InheritFragment) { return((SourceFragment)query); } return(null); } var data = (StatementContent)context.Data; var newitem = (DbNewExpression)data.ItemEpxression; var source = CreateSource(context, content) as QueryBaseFragment; var metadata = data.Table; if (metadata.InheritSets.Length == 0) { TableFragment target = GetRootSource(source) as TableFragment; if (target == null) { target = new TableFragment(context, metadata, data.TargetName); } var update = new UpdateFragment(context, target) { Where = source.Where, Take = source.Take }; update.AddSource(source.Sources); foreach (var item in newitem.Members) { update.SetValue(metadata.Members[(PropertyInfo)item.Key], update.CreateExpression(item.Value)); } return(update); } else { var allmembers = metadata.InheritSets.SelectMany(a => a.Members) .Concat(metadata.Members).ToDictionary(a => a.Member, a => a); InheritFragment inherit = GetRootSource(source) as InheritFragment; if (inherit == null) { inherit = new InheritFragment(context, metadata); } var updates = inherit.Tables.ToDictionary(a => a.Metadata, a => { var target = inherit.Tables.Single(b => b.Metadata == a.Metadata); var update = new UpdateFragment(context, target) { Where = source.Where, Take = source.Take }; update.AddSource(source.Sources); return(update); }); foreach (var item in newitem.Members) { var column = allmembers[(PropertyInfo)item.Key]; var update = updates[column.Table]; foreach (var s in source.Sources) { s.Parent = update; } update.SetValue(column, update.CreateExpression(item.Value)); } var block = new BlockFragment(context); block.Add(updates.Values.Where(a => a.Values.Any()).OfType <ISqlFragment>()); return(block); } }
void CheckIntegrity(int[][] table, int expectedLen) { var fragments = new List <TableFragment>(); for (var s = 0; s < table.Length; s++) { var row = table[s]; if (row == null) { continue; } fragments.Add(new TableFragment(row, s)); } var compound = TableFragment.Combine(fragments); var builder = new StringBuilder(); for (var s = 0; s < table.Length; s++) { var offset = compound.GetOffset(s); var row = table[s]; if (row == null) { if (offset >= 0) { builder.Append("row["); builder.Append(s); builder.Append("] should be null but was "); builder.Append(offset); builder.AppendLine(); } } else if (!offset.HasValue) { builder.Append("row["); builder.Append(s); builder.Append("] should be non-null but was null"); builder.AppendLine(); } else { for (var c = 0; c < row.Length; c++) { var expected = row[c]; var actual = compound[offset.Value + c]; if (expected != actual) { builder.Append("row["); builder.Append(s); builder.Append("]["); builder.Append(c); builder.Append("] should be "); builder.Append(expected); builder.Append(" but was "); builder.Append(actual); builder.AppendLine(); } } } } Assert.That(builder.ToString(), Is.EqualTo(string.Empty)); Assert.That(compound.Count, Is.EqualTo(expectedLen)); }
static CompressedBlob ExtractTransitionTableBlob(Config config, Statistics statistics, TableData data) { var graph = config.Graph.Graph; var actionsList = new int[data.StateMap.Count]; var lastGotoStateIndex = data.StateMap.Count; var fragments = new List <TableFragment>(); foreach (var state in graph.States) { var index = data.StateMap[state]; var transitionRow = ExtractTransitionRow(data, state); var gotoRow = ExtractGotoRow(data, state); if (transitionRow.Fragment == null) { actionsList[index] = transitionRow.ShortCircuitReduction; statistics.StatesShortCircuited++; if (gotoRow != null) { statistics.StatesWithGotos++; } } else { fragments.Add(transitionRow.Fragment); if (transitionRow.HasReduction && transitionRow.HasShift) { statistics.StatesWithSRConflicts++; } if (gotoRow != null) { statistics.StatesWithGotos++; } else if (!transitionRow.HasReduction || !transitionRow.HasShift) { statistics.StatesOther++; } } if (gotoRow != null) { fragments.Add(gotoRow); statistics.NonTerminalColumns = Math.Max(statistics.NonTerminalColumns, gotoRow.Count); lastGotoStateIndex = data.StateMap[state] + 1; } } var combined = TableFragment.Combine(fragments); var offsetSectionLen = graph.States.Count + lastGotoStateIndex; Array.Resize(ref actionsList, offsetSectionLen + combined.Count); for (var i = 0; i < graph.States.Count << 1; i++) { var offset = combined.GetOffset(i); if (offset.HasValue) { actionsList[i] = offset.Value + offsetSectionLen; } } combined.CopyTo(actionsList, offsetSectionLen); var actionsBlob = CompressedBlob.Compress(config.Manager.TableCompression, ElementSizeStrategy.Get(config.Manager.ElementSize), actionsList); statistics.ActionsRunTime = actionsList.Length; statistics.ActionsAssemblyBytes = actionsBlob.Bytes; statistics.GotoOffsetsLen = lastGotoStateIndex; return(actionsBlob); }
public void CheckTable <T>(List <T> expectedTable, int tableIndex = 0) { expectedTable = ReplaceTable(expectedTable, _context.Rate, _context.Amount, null, null, null, _context.Fee, _context.Email ?? _context.PhoneNumber); TableFragment.CheckTablesWithOrder(_context.Grid, multiformLocator, expectedTable, tableIndex); }
public void UserSeeQuittanceReceiverTable(List <UIWMPaymentTable> expectedTable) { expectedTable = ReplaceTable(expectedTable, _context.Rate, _context.Amount, null, null, null, _context.Fee, _context.Email); TableFragment.CheckTables(_context.Grid, multiformLocator, expectedTable, 2); CommonComponentSteps.MakeScreenshot(); }
/// <summary> /// 生成插入单个数据对象语句,对象的主键是标识列。 /// </summary> /// <param name="context">生成上下文。</param> /// <returns>语句片段。</returns> protected virtual SqlFragment GenerateForInsertIdentitySingle(GenerateContext context) { var getidentity = context.Translate(Expression.Call(null, SupportMembers.DbFunctions.GetIdentity)); var data = (GenerateDataForInsert)context.Data; var identityunit = (CommitIdentityUnit)data.MainUnit; var keyVars = new Dictionary <ColumnMetadata, VariableFragment>(); var identityCreate = new CreateVariableFragment(context, identityunit.Identity.Metadata.Member.PropertyType); keyVars.Add(identityunit.Identity.Metadata, identityCreate.Name); var block = new BlockFragment(context); if (!context.Feature.HasCapable(EDbCapable.ImplicitDeclareVariable)) { block.Add(identityCreate); } var name = data.TargetName; var maintarget = new TableFragment(context, identityunit.Table, name); { var insert = new InsertValueFragment(context, maintarget, data.CommitObject, data.Items); data.CommitObject.Parent = insert; identityunit.Members.ForEach(member => { if (member.Metadata.IsKey && member.ValueType == ECommitValueType.Expression) { var expMember = (CommitExpressionMember)member; var exp = insert.CreateExpression(expMember.Expression); var expVar = new CreateVariableFragment(context, member.Metadata.Member.PropertyType); block.Add(expVar); block.Add(context.Assign(expVar.Name, exp)); keyVars.Add(member.Metadata, expVar.Name); } else { GenerateForInsertMembers(insert, member); } }); block.Add(insert); block.Add(context.Assign(identityCreate.Name, insert.CreateExpression(getidentity))); } if (data.SubUnits != null) { foreach (var unit in data.SubUnits) { var target = new TableFragment(context, unit.Table); var insert = new InsertValueFragment(context, target, data.CommitObject, data.Items); data.CommitObject.Parent = insert; unit.Keys.ForEach(member => { if (keyVars.TryGetValue(member.Metadata, out VariableFragment value)) { insert.SetValue(member.Metadata, value); } else { GenerateForInsertMembers(insert, member); } }); unit.Members.ForEach(member => GenerateForInsertMembers(insert, member)); block.Add(insert); } } if (data.ReturnMembers.Any()) { ISourceFragment target = maintarget; if (data.SubUnits != null) { target = new InheritFragment(context, data.Table); } var select = new SelectFragment(context, target); select.Members.AddRange(data.ReturnMembers.Select(a => target.GetMember(a.Metadata))); select.Where = data.Table.Keys.Select(key => context.Equal(target.GetMember(key), keyVars.ContainsKey(key) ? (IExpressionFragment)keyVars[key] : data.CommitObject.GetMember(key))).Merge(); block.Add(select); } return(block); }
private SqlFragment GenerateForInsertIdentityMultipleRepeat(GenerateContext context, CommitIdentityUnit mainunit, ColumnMetadata rowindex, TemporaryTableFragment temporaryTable, RowIndexFragment rowindexfragment, GenerateDataForInsert data, out TableFragment whileTarget) { var repeatfragment = new RepeatBlockFragment(context, data.Items); var block = repeatfragment.Block; var whileInsert = context.Insert(temporaryTable, mainunit.Table, mainunit.Members.Where(a => a.ValueType != ECommitValueType.Database).Select(a => a.Metadata)); var whileSelect = (QueryBaseFragment)whileInsert.Query; whileSelect.Where = context.Equal(temporaryTable.GetMember(rowindex), new RowIndexFragment(context)); block.Add(whileInsert); var whileUpdate = new UpdateFragment(context, temporaryTable); var getidentity = whileUpdate.CreateExpression( context.Translate(Expression.Call(null, SupportMembers.DbFunctions.GetIdentity))); whileUpdate.SetValue(mainunit.Identity.Metadata, getidentity); whileUpdate.Where = context.Equal(temporaryTable.GetMember(rowindex), new RowIndexFragment(context)); block.Add(whileUpdate); whileTarget = (TableFragment)whileInsert.Target; return(repeatfragment); }