public void UpdateData(DataScript script) { if (FixedData == null) { FixedData = new InMemoryTable(this); } FixedData = new InMemoryTable(FixedData, script); }
public InMemoryTable ToInMemoryTable() { return(InMemoryTable.FromEnumerable(m_structure, from row in Rows where row.RowState != BedRowState.Detached && row.RowState != BedRowState.Deleted select row )); }
public BedTable(InMemoryTable table) { m_structure = new TableStructure(table.Structure); Rows = new BedRowCollection(this); foreach (var row in table.Rows) { Rows.AddInternal(new BedRow(this, row, BedRowState.Unchanged, m_structure)); } m_defConvertor = new BedValueConvertor(new DataFormatSettings()); }
public InMemoryTable(InMemoryTable oldTable, InMemoryTableOperation op) { Initialize(); m_structure = new TableStructure(op.m_table); var colindexes = op.ColIndexes; foreach (var row in oldTable.Rows) { m_rows.Add(new ArrayDataRecord(row, colindexes, m_structure)); } }
public static InMemoryTable FromEnumerable <T>(ITableStructure table, IEnumerable <T> rows) where T : IBedRecord { var res = new InMemoryTable(); res.m_structure = new TableStructure(table); foreach (IBedRecord rec in rows) { res.m_rows.Add(new ArrayDataRecord(rec)); } return(res); }
public InMemoryTable(InMemoryTable oldTable, DataScript script) { Initialize(); m_structure = new TableStructure(oldTable.Structure); BedTable bt = new BedTable(oldTable); bt.RunScript(script); foreach (IBedRecord rec in bt.Rows) { m_rows.Add(new ArrayDataRecord(rec)); } }
private void LoadFromXml(XmlElement xml, bool oldStyle) { LoadBase(xml); FullName = NameWithSchema.LoadFromXml(xml); if (oldStyle) { foreach (XmlElement child in xml) { var cnt = Constraint.FromXml(child, true); if (cnt != null) { _Constraints.Add(cnt); } else if (child.Name == "Column") { _Columns.Add(new ColumnStructure(child)); } } } else { foreach (XmlElement child in xml.SelectNodes("Column")) { _Columns.Add(new ColumnStructure(child)); } foreach (XmlElement child in xml.SelectNodes("Constraint")) { _Constraints.Add(Constraint.FromXml(child, false)); } } SpecificData = XmlTool.LoadParameters(xml); if (xml.FindElement("Comment") != null) { Comment = xml.FindElement("Comment").InnerText; } if (xml.FindElement("FixedData") != null) { FixedData = new InMemoryTable(this, xml.FindElement("FixedData")); } }
public static DataScript AlterFixedData(InMemoryTable oldData, InMemoryTable newData, InMemoryTableOperation ops, DbDiffOptions opts) { if (newData == null) { return(null); } IPrimaryKey newpk = newData.Structure.FindConstraint <IPrimaryKey>(); if (newpk == null) { return(null); } string[] newcolnames = newData.Structure.Columns.GetNames(); DataScript script = new DataScript(); if (oldData == null) { foreach (var row in newData.Rows) { script.Insert(newcolnames, row.GetValues()); } } else { if (ops != null) { oldData = new InMemoryTable(oldData, ops); } IPrimaryKey oldpk = oldData.Structure.FindConstraint <IPrimaryKey>(); if (oldpk == null) { return(null); } string[] newpkcols = newpk.Columns.GetNames(); string[] oldpkcols = oldpk.Columns.GetNames(); string[] newnopkcols = newData.Structure.GetNoPkColumns().GetNames(); string[] oldnopkcols = oldData.Structure.GetNoPkColumns().GetNames(); foreach (var row in newData.Rows) { object[] newpkvals = row.GetValuesByCols(newpkcols); ArrayDataRecord oldrow = oldData.FindRow(oldpkcols, newpkvals); if (oldrow != null) { object[] oldnopkvals = oldrow.GetValuesByCols(oldnopkcols); object[] newnopkvals = row.GetValuesByCols(newnopkcols); if (BedTool.EqualRecords(oldnopkvals, newnopkvals)) { continue; } // UPDATE List <string> changedcols = new List <string>(); List <object> changedvals = new List <object>(); for (int i = 0; i < oldnopkcols.Length; i++) { if (!BedTool.EqualValues(oldnopkvals[i], newnopkvals[i])) { changedcols.Add(newnopkcols[i]); changedvals.Add(newnopkvals[i]); } } script.Update(newpkcols.ToArray(), newpkvals.ToArray(), changedcols.ToArray(), changedvals.ToArray()); } else { script.Insert(newcolnames, row.GetValues()); } } } if (script.IsEmpty()) { return(null); } return(script); }