Exemple #1
0
 public virtual void ChangeStructure(DatabaseStructure s)
 {
     if (ParentTable != null)
     {
         ParentTable = s.FindByGroupId(ParentTable.GroupId) as TableStructure;
     }
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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);
            }
        }
Exemple #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);
     //}
 }
Exemple #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);
        }
Exemple #7
0
 public override void ChangeStructure(DatabaseStructure s)
 {
     base.ChangeStructure(s);
     foreach (var op in AlterTableOps)
     {
         op.ChangeStructure(s);
     }
 }
Exemple #8
0
        public static DatabaseStructure Load(XmlElement xml)
        {
            DatabaseStructure res = null;

            res = new DatabaseStructure(xml);
            res.MarkAllFilled();
            //res.AfterLoadFix();
            return(res);
        }
Exemple #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());
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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());
        }
Exemple #13
0
        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);
        }
Exemple #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);
        }
Exemple #15
0
 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;
 }
Exemple #16
0
 internal DatabaseStructure GetStructure()
 {
     lock (this)
     {
         WantZip();
         if (m_db == null)
         {
             m_db = LoadStructure();
         }
         return(m_db);
     }
 }
Exemple #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));
        }
            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);
                }
            }
        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();
        }
Exemple #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);
        }
Exemple #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
            });
        }
        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;
        }
Exemple #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);
        }
Exemple #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,
            });
        }
Exemple #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));
         }
     }
 }
Exemple #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);
            }
        }
        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);
        }
Exemple #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);
        }
Exemple #29
0
 public override void ChangeStructure(DatabaseStructure s)
 {
     base.ChangeStructure(s);
     OldObject = s.FindByGroupId(OldObject.GroupId) as AbstractObjectStructure;
 }
Exemple #30
0
        private ITableStructure DoGetRowFormat()
        {
            DatabaseStructure s = Conn.LoadStructure();

            return(s.Tables[m_table]);
        }