Beispiel #1
0
        public MultiTableUpdateScript GetLinkedDataScript(NameWithSchema basetable)
        {
            var res = new MultiTableUpdateScript();

            if (ResultFields == null || !ResultFields.IsMultiTable())
            {
                return(res);
            }
            var pks = new Dictionary <DmlfSource, List <DmlfColumnRef> >();

            foreach (var row in Rows)
            {
                if (row.RowState != BedRowState.Modified)
                {
                    continue;
                }
                var changed = row.GetChangedColumnRefs();
                if (changed.Length == 0)
                {
                    continue;
                }
                var tbls = new List <DmlfSource>();
                foreach (var ch in changed)
                {
                    if (!tbls.Contains(ch.Source))
                    {
                        tbls.Add(ch.Source);
                    }
                }
                foreach (var src in tbls)
                {
                    if (pks.ContainsKey(src))
                    {
                        continue;
                    }
                    pks[src] = ResultFields.GetPrimaryKey(src);
                }

                foreach (var src in tbls)
                {
                    var cols = new List <DmlfColumnRef>();
                    foreach (var ch in changed)
                    {
                        if (ch.Source != src)
                        {
                            continue;
                        }
                        cols.Add(ch);
                    }
                    var pk = pks[src];
                    res.Update(src == DmlfSource.BaseTable ? basetable : src.TableOrView,
                               (from c in pk select c.ColumnName).ToArray(),
                               row.Original.GetValuesByCols(pk.ToArray(), ResultFields),
                               (from c in cols select c.ColumnName).ToArray(),
                               row.GetValuesByCols(cols.ToArray()));
                }
            }

            return(res);
        }
Beispiel #2
0
 public void RenameDomain(NameWithSchema dom, string newname)
 {
     foreach (AbstractObjectStructure obj in this.GetAllObjects())
     {
         obj.NotifyRenameDomain(dom, new NameWithSchema(dom.Schema, newname));
     }
 }
Beispiel #3
0
 public void RenameTable(NameWithSchema tbl, string newname)
 {
     foreach (AbstractObjectStructure obj in this.GetAllObjects())
     {
         obj.NotifyRenameTable(tbl, new NameWithSchema(tbl.Schema, newname));
     }
 }
Beispiel #4
0
 public override void NotifyRenameColumn(NameWithSchema table, string oldcol, string newcol)
 {
     if (Table.FullName == table && ColumnName == oldcol)
     {
         ColumnName = newcol;
     }
 }
Beispiel #5
0
 public override void NotifyRenameDomain(NameWithSchema oldName, NameWithSchema newName)
 {
     if (Domain == oldName)
     {
         Domain = newName;
     }
 }
Beispiel #6
0
 public override void NotifyRenameTable(NameWithSchema oldName, NameWithSchema newName)
 {
     if (FullName == oldName)
     {
         FullName = newName;
     }
 }
Beispiel #7
0
 public static bool GenerateRename(NameWithSchema oldName, NameWithSchema newName, Action <NameWithSchema, string> changeSchema, Action <NameWithSchema, string> rename, bool allowChangeSchema, bool allowRename, DbDiffOptions opts)
 {
     newName = GenerateNewName(oldName, newName, opts);
     if (DbDiffTool.EqualFullNames(oldName, newName, opts))
     {
         return(true);
     }
     if (!EqualSchemas(oldName.Schema, newName.Schema, opts) && !allowChangeSchema)
     {
         return(false);
     }
     if (oldName.Name != newName.Name && !allowRename)
     {
         return(false);
     }
     if (!EqualSchemas(oldName.Schema, newName.Schema, opts))
     {
         changeSchema(oldName, newName.Schema);
     }
     if (oldName.Name != newName.Name)
     {
         rename(new NameWithSchema(newName.Schema, oldName.Name), newName.Name);
     }
     return(true);
 }
Beispiel #8
0
        //public static void RecreateName(this IConstraint cnt)
        //{
        //    if (cnt is IPrimaryKey) cnt.Name = PkName(cnt.Table);
        //    else if (cnt is ForeignKey) cnt.Name = FkName(cnt.Table, ((ForeignKey)cnt).Columns);
        //    else if (cnt is CheckConstraint) cnt.Name = CheckName(cnt.Table);
        //    else if (cnt is UniqueConstraint) cnt.Name = UniqueName(cnt.Table, ((UniqueConstraint)cnt).Columns);
        //}

        public static void RenameTable(TableStructure tbl, IEnumerable tables, NameWithSchema newname)
        {
            var oldname = tbl.FullName;

            tbl.FullName = newname;
            foreach (TableStructure t in tables)
            {
                foreach (Constraint cnt in t.Constraints)
                {
                    var fk = cnt as ForeignKey;
                    if (fk != null)
                    {
                        if (fk.PrimaryKeyTable == oldname)
                        {
                            fk.PrimaryKeyTable = newname;
                            if (fk.Columns.Count == 1 && fk.Columns[0].ColumnName.StartsWith(oldname.Name))
                            {
                                string postfix = fk.Columns[0].ColumnName.Substring(oldname.Name.Length);
                                fk.Columns[0] = new ColumnReference(newname.Name + postfix);
                                ((ColumnStructure)t.Columns[oldname.Name + postfix]).ColumnName = newname.Name + postfix;
                            }
                            fk.Name = DbObjectNameTool.ConstraintName(fk);
                        }
                    }
                }
            }
            foreach (Constraint cnt in tbl.Constraints)
            {
                //cnt.Table = newname;
                cnt.Name = DbObjectNameTool.ConstraintName(cnt);
            }
        }
Beispiel #9
0
 public void ChangeTableSchema(NameWithSchema tbl, string schema)
 {
     foreach (AbstractObjectStructure obj in this.GetAllObjects())
     {
         obj.NotifyRenameTable(tbl, new NameWithSchema(schema, tbl.Name));
     }
 }
Beispiel #10
0
        void editor_ChangedProperties(object sender, EventArgs e)
        {
            var editor = (NewTableChooserFrame)sender;

            m_name = editor.FullName;
            m_db   = editor.Database;
        }
Beispiel #11
0
        public override void SetDummyTable(NameWithSchema name)
        {
            TableStructure table = new TableStructure();

            table.FullName = name;
            table._Constraints.Add(this);
        }
Beispiel #12
0
 public void ChangeDomainSchema(NameWithSchema dom, string schema)
 {
     foreach (AbstractObjectStructure obj in this.GetAllObjects())
     {
         obj.NotifyRenameDomain(dom, new NameWithSchema(schema, dom.Name));
     }
 }
Beispiel #13
0
 public static bool EqualFullNames(NameWithSchema lft, NameWithSchema rgt, DbDiffOptions options)
 {
     if (lft == null || rgt == null)
     {
         return(lft == rgt);
     }
     return(EqualSchemas(lft.Schema, rgt.Schema, options) && EqualNames(lft.Name, rgt.Name, options));
 }
Beispiel #14
0
 public override NameWithSchema RenameObject(NameWithSchema name, string objtype)
 {
     if (name.Schema == m_oldSchema)
     {
         return(new NameWithSchema(m_newSchema, name.Name));
     }
     return(name);
 }
Beispiel #15
0
        //public void AlterTable(ITableStructure oldTable, ITableStructure newTable, DbDiffOptions opts)
        //{
        //    DbDiffTool.AlterTable(oldTable, newTable, opts, this);
        //}

        //public TableStructure AlterTable(NameWithSchema tableName, ITableStructure newTable)
        //{
        //    TableStructure tbl = (TableStructure)Tables[tableName];
        //    tbl.LoadFrom(newTable);
        //    tbl.RepairInconsistency();
        //    return tbl;
        //}

        public void DropTable(NameWithSchema tableName)
        {
            Tables.RemoveIf(t => t.FullName == tableName);
            foreach (TableStructure t in Tables)
            {
                t.DropReferencesTo(tableName);
            }
        }
Beispiel #16
0
        public void RenameSpecificObject(ISpecificObjectStructure obj, NameWithSchema name)
        {
            SpecificObjectStructure o = Structure.FindOrCreateSpecificObject(obj);

            AddOperation(new AlterOperation_RenameSpecificObject {
                OldObject = o, NewName = name
            });
        }
Beispiel #17
0
        public void UpdateData(NameWithSchema table, DataScript script)
        {
            TableStructure tbl = Structure.FindOrCreateTable(table);

            AddOperation(new AlterOperation_UpdateData {
                ParentTable = tbl, Script = script
            });
        }
Beispiel #18
0
        public void RenameTable(ITableStructure table, NameWithSchema name)
        {
            TableStructure tbl = Structure.FindOrCreateTable(table.FullName);

            AddOperation(new AlterOperation_RenameTable {
                OldObject = tbl, NewName = name
            });
        }
Beispiel #19
0
        public void RenameDomain(IDomainStructure domain, NameWithSchema newname)
        {
            DomainStructure dom = Structure.FindOrCreateDomain(domain);

            AddOperation(new AlterOperation_RenameDomain {
                OldObject = dom, NewName = newname
            });
        }
Beispiel #20
0
 public override void NotifyRenameTable(NameWithSchema oldName, NameWithSchema newName)
 {
     base.NotifyRenameTable(oldName, newName);
     if (PrimaryKeyTable == oldName)
     {
         PrimaryKeyTable = newName;
     }
 }
Beispiel #21
0
        //internal void AfterLoadFix()
        //{
        //    foreach (Constraint cnt in Constraints)
        //    {
        //        cnt.Table = FullName;
        //    }
        //}

        public static ITableStructure FromName(NameWithSchema name)
        {
            TableStructure res = new TableStructure();

            res.FullName = name;
            //res.FilledMembers = TableStructureMembers.Name;
            return(res);
        }
        //private void FillBindingTables()
        //{
        //    //colBindingTable.Items.Clear();
        //    //colBindingTable.Items.Add("(SOURCE)");
        //    //for (int i = 0; i < dataGridViewRelations.RowCount; i++)
        //    //{
        //    //    if (dataGridViewRelations.Rows[i].Cells[2].Value == null) continue;
        //    //    string alias = dataGridViewRelations.Rows[i].Cells[4].Value.SafeToString();
        //    //    if (String.IsNullOrEmpty(alias)) colBindingTable.Items.Add(dataGridViewRelations.Rows[i].Cells[2].Value);
        //    //    else colBindingTable.Items.Add(alias);
        //    //}
        //}

        private ITableStructure GetTableStruct(NameWithSchema name)
        {
            if (!m_tables.ContainsKey(name))
            {
                m_tables[name] = m_db.InvokeLoadTableStructure(name, TableStructureMembers.ColumnNames | TableStructureMembers.PrimaryKey);
            }
            return(m_tables[name]);
        }
Beispiel #23
0
        public static string CheckName(NameWithSchema table)
        {
            StringBuilder name = new StringBuilder();

            name.Append("CHK_");
            name.Append(table.Name);
            return(name.ToString());
        }
 ITableStructure IDmlfHandler.GetStructure(NameWithSchema name)
 {
     if (name == null)
     {
         return(m_table);
     }
     return(GetTableStruct(name));
 }
Beispiel #25
0
        protected virtual void LoadViewAsTable(NameWithSchema name)
        {
            string sql = "SELECT * FROM " + m_dialect.QuoteFullName(name);
            var    ts  = CachedQueryStructure(sql);

            ts.FullName = name;
            m_db.ViewAsTables.Add(ts);
        }
Beispiel #26
0
 public static bool IsSystemObject(this ISqlDialect dialect, string objtype, NameWithSchema name)
 {
     if (name == null)
     {
         return(false);
     }
     return(dialect.IsSystemObject(objtype, name.Schema, name.Name));
 }
 private string GetFullName(NameWithSchema name)
 {
     if (m_settings.AddSchema && !name.Schema.IsEmpty())
     {
         return(GetShortName(name.Schema) + "." + GetShortName(name.Name));
     }
     return(GetShortName(name.Name));
 }
Beispiel #28
0
 public static string SafeGetSchema(this NameWithSchema name)
 {
     if (name != null)
     {
         return(name.Schema);
     }
     return(null);
 }
Beispiel #29
0
        //DatabaseStructureMembers IDatabaseStructure.FilledMembers
        //{
        //    get { return FilledMembers; }
        //}

        #endregion

        public TableStructure AddTable(NameWithSchema name)
        {
            TableStructure res = new TableStructure();

            //res.FilledMembers = TableStructureMembers.Name;
            res.FullName = name;
            Tables.Add(res);
            return(res);
        }
Beispiel #30
0
        public void ReorderColumns(NameWithSchema table, List <string> newColumnOrder)
        {
            var t = FindTable(table);

            if (t != null)
            {
                t.ReorderColumns(newColumnOrder);
            }
        }