Esempio n. 1
0
        //public void SaveToXml(XmlElement xml)
        //{
        //    foreach (var elem in Inserts)
        //    {
        //        elem.SaveToXml(xml.AddChild("Insert"));
        //    }
        //    foreach (var elem in Updates)
        //    {
        //        elem.SaveToXml(xml.AddChild("Update"));
        //    }
        //    foreach (var elem in Deletes)
        //    {
        //        elem.SaveToXml(xml.AddChild("Delete"));
        //    }
        //}

        //private void DumpTarget(ISqlDumper dmp, ChangeSetItem item)
        //{
        //    string linkedInfoStr = item.LinkedInfo != null ? item.LinkedInfo.ToString() : "";
        //    dmp.Put("%s%f", linkedInfoStr, item.TargetTable);
        //}

        //private void DumpWhere(ISqlDumper dmp, ChangeSetItem item, List<ChangeSetCondition> conditions, DatabaseInfo db)
        //{
        //    dmp.Put("^ where ");
        //    bool wasCond = false;
        //    foreach(var cond in conditions)
        //    {
        //        if (wasCond) dmp.Put(" ^and ");
        //        wasCond = true;
        //        DumpCondition(dmp, item, cond, db);
        //    }
        //}

        public DmlfBatch GetCommands(DatabaseInfo db, IDatabaseFactory factory)
        {
            var disableFks = new HashSet<Tuple<NameWithSchema, string>>();
            var dda = factory.CreateDataAdapter();
            var converter = new CdlValueConvertor(new DataFormatSettings());

            foreach (var upd in Updates)
            {
                if (upd.DisableReferencedForeignKeys || upd.UpdateReferences || DisableReferencedForeignKeys || UpdateReferences)
                {
                    var table = db.FindTable(upd.TargetTable);
                    if (table == null) continue;
                    foreach (var fk in table.GetReferences())
                    {
                        disableFks.Add(Tuple.Create(fk.OwnerTable.FullName, fk.ConstraintName));
                    }
                }
            }

            var res = new DmlfBatch();

            foreach (var fk in disableFks) res.DisableConstraint(fk.Item1, fk.Item2, true);

            foreach (var ins in Inserts)
            {
                ins.GetCommands(res, db, dda, converter);
            }

            foreach (var upd in Updates)
            {
                upd.GetInsertCommands(res, db, this, dda, converter);
            }

            foreach (var upd in Updates)
            {
                upd.GetCommands(res, db, this, dda, converter);
            }

            foreach (var upd in Updates)
            {
                upd.GetDeleteCommands(res, db, this);
            }

            foreach (var del in Deletes)
            {
                del.GetCommands(res, db, this);
            }

            foreach (var fk in disableFks) res.DisableConstraint(fk.Item1, fk.Item2, false);

            res.Commands.ForEach(x =>
                {
                    var cmd = x as DmlfCommandBase;
                    if (cmd != null) cmd.SimplifyFromAliases();
                });

            return res;
        }
Esempio n. 2
0
 public CdlTable(InMemoryTable table)
 {
     m_structure = table.Structure.CloneTable();
     Rows        = new CdlRowCollection(this);
     foreach (var row in table.Rows)
     {
         Rows.AddInternal(new CdlRow(this, row, CdlRowState.Unchanged, m_structure));
     }
     m_defConvertor = new CdlValueConvertor(new DataFormatSettings());
 }
Esempio n. 3
0
 public CdlTable(TableInfo structure)
 {
     m_structure    = structure.CloneTable();
     Rows           = new CdlRowCollection(this);
     m_defConvertor = new CdlValueConvertor(new DataFormatSettings());
 }
Esempio n. 4
0
 public CdlRecordAdapter()
 {
     m_convertor = new CdlValueConvertor(new DataFormatSettings());
     m_value = new CdlValueHolder();
 }
Esempio n. 5
0
 public CdlRecordAdapter()
 {
     m_convertor = new CdlValueConvertor(new DataFormatSettings());
     m_value     = new CdlValueHolder();
 }