コード例 #1
0
 public virtual void ChangeStructure(DatabaseStructure s)
 {
     if (ParentTable != null)
     {
         ParentTable = s.FindByGroupId(ParentTable.GroupId) as TableStructure;
     }
 }
コード例 #2
0
        public override void WriteStructureAfterData(IDatabaseStructure db)
        {
            var index_e = m_zip.PutNextEntry("_index_.xml");
            var dbcopy  = new DatabaseStructure(db);

            dbcopy.Save(m_zip);
        }
コード例 #3
0
        public void CreateAllObjects(IDatabaseSource conn, ISqlDumper dmp, ISqlDialect dialect)
        {
            var dbmem = new DatabaseStructureMembers
            {
                TableList             = true,
                TableMembers          = TableStructureMembers.AllNoRefs,
                DomainList            = true,
                DomainDetails         = true,
                SpecificObjectList    = true,
                SpecificObjectDetails = true,
                LoadDependencies      = true,
                IgnoreSystemObjects   = true,
            };
            var dbs   = new DatabaseStructure(conn.InvokeLoadStructure(dbmem, null));
            var props = new CreateDatabaseObjectsProps
            {
                CreateDomains         = Domains,
                CreateFixedData       = FixedData,
                CreateSchemata        = Schemata,
                CreateSpecificObjects = SpecificObjects,
                CreateTables          = Tables
            };
            IMigrationProfile profile = dialect.CreateMigrationProfile();

            dialect.MigrateDatabase(dbs, profile, null);

            dmp.CreateDatabaseObjects(dbs, props);
        }
コード例 #4
0
        public void GenerateDropAllTables(IDatabaseSource conn, ISqlDumper dmp, ISqlDialect dialect)
        {
            DatabaseStructureMembers dbmem = new DatabaseStructureMembers
            {
                TableList           = true,
                TableMembers        = TableStructureMembers.ForeignKeys,
                IgnoreSystemObjects = true,
            };
            var dbs = new DatabaseStructure(conn.InvokeLoadStructure(dbmem, null));
            IMigrationProfile profile = dialect.CreateMigrationProfile();

            dialect.MigrateDatabase(dbs, profile, null);
            foreach (ITableStructure tbl in dbs.Tables)
            {
                if (conn.Dialect.IsSystemTable(tbl.FullName))
                {
                    continue;
                }
                foreach (IForeignKey fk in tbl.GetConstraints <IForeignKey>())
                {
                    dmp.DropConstraint(fk);
                }
            }
            foreach (ITableStructure tbl in dbs.Tables)
            {
                if (conn.Dialect.IsSystemTable(tbl.FullName))
                {
                    continue;
                }
                dmp.DropTable(tbl, DropFlags.None);
            }
        }
コード例 #5
0
 public override void WriteStructureBeforeData(IDatabaseStructure db)
 {
     if (m_db.DatabaseCaps.ExecuteSql)
     {
         DatabaseStructure dbcopy = new DatabaseStructure(db);
         if (!Dialect.DialectCaps.UncheckedReferences)
         {
             foreach (TableStructure tbl in dbcopy.Tables)
             {
                 tbl.RemoveConstraints <IForeignKey>();
             }
         }
         m_db.InvokeScript(dmp => { dmp.CreateDatabaseObjects(dbcopy); }, ProgressInfo);
         m_db.InvokeScript(dmp => SqlTemplates.GenerateInsertFixedData(dmp, dbcopy), ProgressInfo);
     }
     else
     {
         var d0 = new DatabaseStructure();
         d0.GroupId = db.GroupId;
         m_db.AlterDatabase(d0, db);
     }
     //foreach (var tbl in db.Tables)
     //{
     //    Logging.Debug("Creating table {0}", tbl.FullName);
     //    SetCurWork(String.Format("{0} {1}", Texts.Get("s_creating_table"), tbl.FullName));
     //    TableStructure tsNoFk = new TableStructure(tbl);
     //    tsNoFk.RemoveConstraints<IForeignKey>();
     //    m_db.CreateTable(tsNoFk);
     //}
 }
コード例 #6
0
        public static void CreateObject(this IDatabaseSource conn, IAbstractObjectStructure obj)
        {
            DatabaseStructure oldDb = new DatabaseStructure();
            DatabaseStructure newDb = new DatabaseStructure(oldDb);

            newDb.AddObject(obj, true);
            conn.AlterDatabase(oldDb, newDb);
        }
コード例 #7
0
 public override void ChangeStructure(DatabaseStructure s)
 {
     base.ChangeStructure(s);
     foreach (var op in AlterTableOps)
     {
         op.ChangeStructure(s);
     }
 }
コード例 #8
0
ファイル: DbDatabase.cs プロジェクト: janproch/datadmin
        public static DatabaseStructure Load(XmlElement xml)
        {
            DatabaseStructure res = null;

            res = new DatabaseStructure(xml);
            res.MarkAllFilled();
            //res.AfterLoadFix();
            return(res);
        }
コード例 #9
0
        public static void DropObject(this IDatabaseSource conn, IAbstractObjectStructure obj)
        {
            DatabaseStructure oldDb = new DatabaseStructure();

            oldDb.AddObject(obj, true);
            DatabaseStructure newDb = new DatabaseStructure(oldDb);

            newDb.DropObject(obj);
            conn.AlterDatabase(oldDb, newDb, DbDiffOptions.AlterStructureOptions());
        }
コード例 #10
0
        public static TableStructure CloneWithDb(this ITableStructure table)
        {
            if (table.Database == null)
            {
                return(new TableStructure(table));
            }
            var db = new DatabaseStructure(table.Database);

            return((from t in db.Tables where t.GroupId == table.GroupId select t).FirstOrDefault() as TableStructure);
        }
コード例 #11
0
        public RecreatedItem CloneForStructure(DatabaseStructure s)
        {
            var res = new RecreatedItem();

            res.RecreatedObject = s.FindByGroupId(RecreatedObject.GroupId) as AbstractObjectStructure;
            if (NewVersion != null)
            {
                res.NewVersion = NewVersion.CloneObject();
            }
            return(res);
        }
コード例 #12
0
        public static void ChangeObject(this IDatabaseSource conn, IAbstractObjectStructure oldObj, Action <AbstractObjectStructure> changeFunc)
        {
            DatabaseStructure oldDb = new DatabaseStructure();

            oldDb.AddObject(oldObj, true);
            DatabaseStructure       newDb  = new DatabaseStructure(oldDb);
            AbstractObjectStructure newObj = (AbstractObjectStructure)newDb.FindByGroupId(oldObj);

            changeFunc(newObj);
            conn.AlterDatabase(oldDb, newDb, DbDiffOptions.AlterStructureOptions());
        }
コード例 #13
0
ファイル: DbDiff_Database.cs プロジェクト: janproch/datadmin
        public static DbObjectPairing CreateTablePairing(ITableStructure oldTable, ITableStructure newTable)
        {
            DatabaseStructure src = new DatabaseStructure();
            DatabaseStructure dst = new DatabaseStructure(src);

            src.AddObject(oldTable, true);
            dst.AddObject(newTable, true);
            DbObjectPairing pairing = new DbObjectPairing(src, dst);

            return(pairing);
        }
コード例 #14
0
        public AlterOperation CloneForStructure(DatabaseStructure s)
        {
            Type t   = GetType();
            var  res = t.GetConstructor(new Type[] { }).Invoke(new object[] { }) as AlterOperation;

            res.AssignFrom(this);
            if (s != null)
            {
                res.ChangeStructure(s);
            }
            return(res);
        }
コード例 #15
0
ファイル: DialectBase.cs プロジェクト: janproch/datadmin
 public virtual void MigrateDatabase(DatabaseStructure db, IMigrationProfile profile, IProgressInfo progress)
 {
     if (db.Dialect.SameDialect(this))
     {
         return;
     }
     foreach (TableStructure table in db.Tables)
     {
         MigrateTable(table, profile, progress);
     }
     db.Dialect = this;
 }
コード例 #16
0
 internal DatabaseStructure GetStructure()
 {
     lock (this)
     {
         WantZip();
         if (m_db == null)
         {
             m_db = LoadStructure();
         }
         return(m_db);
     }
 }
コード例 #17
0
        public override void Run(IAlterProcessor proc, DbDiffOptions opts)
        {
            var newtbl = new TableStructure(ParentTable);
            var dbs    = new DatabaseStructure();

            dbs.Tables.Add(newtbl);
            foreach (var op in AlterTableOps)
            {
                op.Run(dbs, opts);
            }
            proc.RecreateTable(ParentTable, newtbl);
            opts.AlterLogger.Info(Texts.Get("s_recreated$table", "table", ParentTable.FullName));
        }
コード例 #18
0
            public override void RunCommand()
            {
                if (Format == null)
                {
                    if (Outfile.EndsWith(".dbk"))
                    {
                        Format = "dbk";
                    }
                    else if (Outfile.EndsWith(".ddf"))
                    {
                        Format = "ddf";
                    }
                    else
                    {
                        throw new CommandLineError("DAE-00151 Unknown output format, cannot be deduced from file extension");
                    }
                }
                IDatabaseSource db = m_connection.GetConnection();

                Async.SafeOpen(db.Connection);
                try
                {
                    switch (Format)
                    {
                    case "ddf":
                    {
                        var s = new DatabaseStructure(db.InvokeLoadStructure(DatabaseStructureMembers.FullStructure, null));
                        s.Save(Outfile);
                    }
                    break;

                    case "dbk":
                    {
                        DataArchiveWriter dw = new DataArchiveWriter();
                        dw.FilePlace = FilePlaceAddonType.PlaceFromVirtualFile(Outfile);
                        CopyDbJob.CopyDatabase(db, dw, null, new DatabaseCopyOptions {
                                CopyMembers = DatabaseStructureMembers.FullStructure
                            });
                        Async.SafeClose(db.Connection);
                    }
                    break;

                    default:
                        throw new CommandLineError("DAE-00152 Unknown format:" + Format);
                    }
                }
                finally
                {
                    Async.SafeClose(db.Connection);
                }
            }
コード例 #19
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
            var db = new DatabaseStructure();

            if (m_editor != null)
            {
                m_editor.SaveToStructure(db);
            }
            m_props.SpecificData = new Dictionary <string, string>();
            m_props.SpecificData.AddAll(db.SpecificData);
            m_props.Name = tbxName.Text;
            Close();
        }
コード例 #20
0
        public void CreateReferences(IDatabaseSource conn, ISqlDumper dmp, ISqlDialect dialect)
        {
            var dbmem = new DatabaseStructureMembers
            {
                TableList           = true,
                TableMembers        = TableStructureMembers.AllNoRefs,
                IgnoreSystemObjects = true,
            };
            var dbs = new DatabaseStructure(conn.InvokeLoadStructure(dbmem, null));
            IMigrationProfile profile = dialect.CreateMigrationProfile();

            dialect.MigrateDatabase(dbs, profile, null);
            CreateReferences(dmp, dbs);
        }
コード例 #21
0
        public virtual void WriteStructureBeforeData(IDatabaseStructure db)
        {
            // create tables without foreign keys
            DatabaseStructure dbcopy = new DatabaseStructure(db);

            foreach (TableStructure tbl in dbcopy.Tables)
            {
                tbl.RemoveConstraints <IForeignKey>();
            }
            m_dmp.CreateDatabaseObjects(dbcopy, new CreateDatabaseObjectsProps
            {
                CreateSpecificObjects = false
            });
        }
コード例 #22
0
        public DatabasePropertiesForm(DatabaseProperties props, IDatabaseSource conn, bool readOnlyName)
        {
            InitializeComponent();
            m_props = props;
            DatabaseStructure dbs = new DatabaseStructure();

            dbs.SpecificData.AddAll(props.SpecificData);
            if (conn.Dialect != null)
            {
                m_editor = conn.Dialect.GetSpecificEditor(dbs, conn);
            }
            propertyFrame1.SelectedObject = m_editor;
            tbxName.ReadOnly = readOnlyName;
            tbxName.Text     = props.Name;
        }
コード例 #23
0
        public void CreateDomains(IDatabaseSource conn, ISqlDumper dmp, ISqlDialect dialect)
        {
            var dbmem = new DatabaseStructureMembers
            {
                DomainDetails       = true,
                DomainList          = true,
                IgnoreSystemObjects = true,
            };
            var dbs = new DatabaseStructure(conn.InvokeLoadStructure(dbmem, null));
            IMigrationProfile profile = dialect.CreateMigrationProfile();

            dialect.MigrateDatabase(dbs, profile, null);

            CreateDomains(dmp, dbs);
        }
コード例 #24
0
        public void CreateTables(ISqlDumper dmp, IDatabaseStructure db)
        {
            // create tables without foreign keys
            DatabaseStructure dbcopy = new DatabaseStructure(db);

            foreach (TableStructure tbl in dbcopy.Tables)
            {
                RemoveUnwantedTableFeature(tbl);
            }
            dmp.CreateDatabaseObjects(dbcopy, new CreateDatabaseObjectsProps
            {
                AllFlags     = false,
                CreateTables = true,
            });
        }
コード例 #25
0
 public DatabaseStructure LoadStructure()
 {
     lock (this)
     {
         if (!m_zip.ContainsEntry("_index_.xml"))
         {
             throw new ArchiveError("DAE-00194 Bad data archive: missing file _index_.xml");
         }
         ZipEntry entry = m_zip["_index_.xml"];
         using (Stream fr = entry.OpenReader())
         {
             return(DatabaseStructure.Load(fr));
         }
     }
 }
コード例 #26
0
        public void FillAllTables(IDatabaseSource conn, ISqlDumper dmp, ISqlDialect dialect)
        {
            var dbmem = new DatabaseStructureMembers
            {
                TableList    = true,
                TableMembers = TableStructureMembers.Columns,
            };
            var dbs = new DatabaseStructure(conn.InvokeLoadStructure(dbmem, null));
            IMigrationProfile profile = dialect.CreateMigrationProfile();

            dialect.MigrateDatabase(dbs, profile, null);
            foreach (var tbl in dbs.Tables)
            {
                GenerateFillTable(tbl, dmp);
            }
        }
コード例 #27
0
        public static DatabaseStructure GetMappedDatabase(this IDatabaseStructure db, DatabaseCopyOptions copyOpts, ISqlDialect dialect)
        {
            DatabaseStructure res = new DatabaseStructure(db, copyOpts.CopyMembers);

            foreach (TableStructure tbl in res.Tables)
            {
                tbl.RemoveInvalidReferences(copyOpts, dialect);
                //tbl.MangleMappedTable(copyOpts, dialect);
            }
            if (copyOpts.SchemaMode == DbCopySchemaMode.Explicit)
            {
                // no schemata will be created
                res.Schemata.Clear();
                res.RunNameTransformation(new SetSchemaNameTransformation(copyOpts.ExplicitSchema));
            }
            return(res);
        }
コード例 #28
0
        public static void AlterObject(this IDatabaseSource conn, IAbstractObjectStructure oldObj, IAbstractObjectStructure newObj, DbDiffOptions options)
        {
            if (oldObj == null)
            {
                conn.CreateObject(newObj);
                return;
            }
            if (newObj == null)
            {
                conn.DropObject(oldObj);
                return;
            }
            if (oldObj.GroupId != newObj.GroupId)
            {
                throw new InternalError("DAE-00010 Altering object with different groupid");
            }
            DatabaseStructure oldDb = new DatabaseStructure();
            DatabaseStructure newDb = new DatabaseStructure(oldDb);

            oldDb.AddObject(oldObj, true);
            newDb.AddObject(newObj, true);
            conn.AlterDatabase(oldDb, newDb, options);
        }
コード例 #29
0
 public override void ChangeStructure(DatabaseStructure s)
 {
     base.ChangeStructure(s);
     OldObject = s.FindByGroupId(OldObject.GroupId) as AbstractObjectStructure;
 }
コード例 #30
0
        private ITableStructure DoGetRowFormat()
        {
            DatabaseStructure s = Conn.LoadStructure();

            return(s.Tables[m_table]);
        }