Exemple #1
0
 public void UpdateData(DataScript script)
 {
     if (FixedData == null)
     {
         FixedData = new InMemoryTable(this);
     }
     FixedData = new InMemoryTable(FixedData, script);
 }
Exemple #2
0
 public InMemoryTable ToInMemoryTable()
 {
     return(InMemoryTable.FromEnumerable(m_structure,
                                         from row in Rows
                                         where row.RowState != BedRowState.Detached && row.RowState != BedRowState.Deleted
                                         select row
                                         ));
 }
Exemple #3
0
 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());
 }
Exemple #4
0
        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));
            }
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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));
            }
        }
Exemple #7
0
 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"));
     }
 }
Exemple #8
0
        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);
        }