コード例 #1
0
ファイル: MigrateTool.cs プロジェクト: janproch/datadmin
        public static void RemoveNonPk1AutoIncrements(TableStructure table, IProgressInfo progress)
        {
            IPrimaryKey pk = table.FindConstraint <IPrimaryKey>();

            foreach (ColumnStructure col in table.Columns)
            {
                var type = col.DataType;
                if (type is DbTypeInt && ((DbTypeInt)type).Autoincrement)
                {
                    if (pk == null || pk.Columns.Count != 1 || pk.Columns[0].ColumnName != col.ColumnName)
                    {
                        type.SetAutoincrement(false);
                        progress.LogMessage("migrate", LogLevel.Warning, "Removed autoincrement flag, column {0}.{1} is not primary key", table.FullName, col.ColumnName);
                    }
                }
            }
        }
コード例 #2
0
        public static void RaiseErrorEx(this IProgressInfo progress, Exception err, string message, string category)
        {
            string longmsg = String.Format("{0} ({1})", message, err.Message);

            if (category != null)
            {
                progress.LogMessage(category, LogLevel.Error, longmsg);
            }
            Logging.Error("Error: {0}; {1}", message, err);
            if (progress != null)
            {
                progress.RaiseError(longmsg);
            }
            else
            {
                throw new Exception(message, err);
            }
        }
コード例 #3
0
ファイル: AccessDialect.cs プロジェクト: janproch/datadmin
        public override DbTypeBase MigrateDataType(IColumnStructure owningColumn, DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            var stype = type as DbTypeString;

            if (stype != null)
            {
                if (stype.Length > 255)
                {
                    string msg = Texts.Get("s_reduced_column_length$column$oldlen$newlen",
                                           "column", owningColumn.Table.ToString() + "." + owningColumn.ColumnName,
                                           "oldlen", stype.Length,
                                           "newlen", 255);
                    progress.LogMessage("TABLE", LogLevel.Warning, msg);
                    Logging.Info(msg);
                    stype.Length = 255;
                    return(stype);
                }
            }
            return(base.MigrateDataType(owningColumn, type, profile, progress));
        }
コード例 #4
0
        public virtual void CreateDatabaseObjects(IDatabaseStructure db, CreateDatabaseObjectsProps props)
        {
            if (Dialect.DialectCaps.Domains && props.CreateDomains)
            {
                foreach (var domain in db.Domains)
                {
                    try
                    {
                        CreateDomain(domain);
                    }
                    catch (Exception err)
                    {
                        ProgressInfo.RaiseErrorEx(err, "DAE-00244 " + Texts.Get("s_error_creating$domain", "domain", domain.FullName), "DOMAIN");
                    }
                }
            }
            if (Dialect.DialectCaps.MultipleSchema && props.CreateSchemata)
            {
                foreach (var schema in db.Schemata)
                {
                    try
                    {
                        CreateSchema(schema);
                    }
                    catch (Exception err)
                    {
                        ProgressInfo.RaiseErrorEx(err, "DAE-00245 " + Texts.Get("s_error_creating$schema", "schema", schema.SchemaName), "SCHEMA");
                    }
                }
            }
            var refsToCreate = new List <IForeignKey>();

            if (props.CreateTables)
            {
                foreach (var tbl in db.Tables)
                {
                    ITableStructure tbl2 = tbl;
                    if (!Dialect.DialectCaps.UncheckedReferences)
                    {
                        var newtbl = new TableStructure(tbl);
                        foreach (ForeignKey fk in new List <ForeignKey>(newtbl.GetConstraints <ForeignKey>()))
                        {
                            newtbl._Constraints.Remove(fk);
                            fk.SetDummyTable(tbl.FullName);
                            refsToCreate.Add(fk);
                        }
                        tbl2 = newtbl;
                    }

                    Logging.Debug("Creating table {0}", tbl2.FullName);
                    SetCurWork(String.Format("{0} {1}", Texts.Get("s_creating_table"), tbl2.FullName));
                    if (m_props.DumpWriterConfig != null && m_props.DumpWriterConfig.IncludeDropStatement)
                    {
                        DropTable(tbl2, DropFlags.TestIfExist);
                    }
                    try
                    {
                        CreateTable(tbl2);
                    }
                    catch (Exception err)
                    {
                        ProgressInfo.RaiseErrorEx(err, "DAE-00246 " + Texts.Get("s_error_creating$table", "table", tbl2.FullName), "TABLE");
                    }
                }
            }
            if (props.CreateFixedData)
            {
                foreach (var tbl in db.Tables)
                {
                    this.UpdateData(tbl, DbDiffTool.AlterFixedData(null, tbl.FixedData, null, new DbDiffOptions()), null);
                }
            }
            foreach (var fk in refsToCreate)
            {
                CreateConstraint(fk);
            }
            if (props.CreateSpecificObjects)
            {
                foreach (var obj in db.GetSpecObjectsOrderByDependency())
                {
                    SetCurWork(String.Format("{0} {1}", Texts.Get("s_creating_object"), obj.ObjectName));
                    if (m_props.DumpWriterConfig != null && m_props.DumpWriterConfig.IncludeDropStatement)
                    {
                        DropSpecificObject(obj, DropFlags.TestIfExist);
                    }
                    try
                    {
                        CreateSpecificObject(obj);
                    }
                    catch (Exception err)
                    {
                        if (ProgressInfo != null)
                        {
                            ProgressInfo.LogMessage("s_create_object", LogLevel.Error, Texts.Get("s_error_creating_object$name", "name", obj.ObjectName) + ": " + err.Message);
                        }
                        Logging.Error("Error creating object:" + err.ToString());
                    }
                }
            }
        }