示例#1
0
 // constructor 3
 public DbDefSource(IDatabaseStructure db, ReadOnly flag)
 {
     m_readOnlyStructure = new DatabaseStructure(db);
     m_readOnlyStructure.MarkAllFilled();
     m_openedReadOnly = true;
     m_conn           = new DbDefConnection(m_readOnlyStructure);
 }
示例#2
0
 public static void GenerateInsertFixedData(ISqlDumper dmp, IDatabaseStructure db)
 {
     foreach (var ts in db.Tables)
     {
         GenerateInsertFixedData(dmp, ts);
     }
 }
示例#3
0
 public override void WriteStructureAfterData(IDatabaseStructure db)
 {
     using (FileStream fw = new FileStream(GetWorkingFileName(), FileMode.Create))
     {
         m_db.Save(fw);
     }
 }
示例#4
0
 public void CreateReferences(ISqlDumper dmp, IDatabaseStructure db)
 {
     foreach (var table in db.Tables)
     {
         dmp.CreateConstraints(table.GetConstraints <IForeignKey, IConstraint>());
     }
 }
示例#5
0
 public void CreateDomains(ISqlDumper dmp, IDatabaseStructure db)
 {
     foreach (var dom in db.Domains)
     {
         dmp.CreateDomain(dom);
     }
 }
示例#6
0
 public DbDefChooseSpecObjectTreeNode(DbDefChooseSpecObjectsTreeNode parent, ISpecificObjectStructure obj)
     : base(parent, obj.ObjectName.ToString())
 {
     m_repr = SpecificRepresentationAddonType.Instance.FindRepresentation(obj.ObjectType);
     m_obj  = obj;
     m_db   = parent.m_db;
 }
示例#7
0
 public string[] GetEngines()
 {
     if (m_engines == null)
     {
         var dbmem = new DatabaseStructureMembers();
         dbmem.SpecificObjectOverride["mysql.engine"]            = new SpecificObjectMembers();
         dbmem.SpecificObjectOverride["mysql.engine"].ObjectList = true;
         IDatabaseStructure cat = m_db.InvokeLoadStructure(dbmem, null);
         List <string>      res = new List <string>();
         if (cat.SpecificObjects.ContainsKey("mysql.engine"))
         {
             foreach (var c in cat.SpecificObjects["mysql.engine"])
             {
                 res.Add(c.ObjectName.Name);
             }
         }
         else
         {
             res.Add("InnoDB");
             res.Add("MyISAM");
         }
         m_engines = res.ToArray();
     }
     return(m_engines);
 }
示例#8
0
        public MsSqlDatabaseEditor(IDatabaseStructure db, IDatabaseSource conn)
        {
            m_db   = db;
            m_conn = conn;

            Collation = m_db.SpecificData.Get("mssql.collation");
        }
示例#9
0
 public DbDefChooseSpecObjectsTreeNode(DbDefChooseTreeNode parent, string objtype)
     : base(parent, objtype + "_list")
 {
     m_repr    = SpecificRepresentationAddonType.Instance.FindRepresentation(objtype);
     m_objtype = objtype;
     m_db      = parent.m_db;
 }
示例#10
0
        //private void selectTemplateComboFrame1_ChangedSelectedItem(object sender, EventArgs e)
        //{
        //    RecreateBackupFormat();
        //}

        //private void RecreateBackupFormat()
        //{
        //    AddonHolder item = selectTemplateComboFrame1.SelectedAddonHolder;
        //    if (item != null) m_format = (IBackupFormat)item.CreateInstance();
        //    else m_format = new DataArchiveBackupFormat();
        //    propertyFrame1.SelectedObject = m_format;
        //}

        private void InitPropertiesPage()
        {
            try
            {
                Async.SafeOpen(m_source.Connection);
                DatabaseStructureMembers dbmem = new DatabaseStructureMembers
                {
                    TableList           = true,
                    SpecificObjectList  = true,
                    SchemaList          = true,
                    IgnoreSystemObjects = true,
                };
                IDatabaseStructure dbs = m_source.InvokeLoadStructure(dbmem, null);
                if (m_chooseNode == null)
                {
                    m_chooseNode    = new DbDefChooseTreeNode(dbs);
                    treObjects.Root = m_chooseNode;
                }
            }
            catch (Exception err)
            {
                Errors.Report(err);
                wizard1.Back();
            }
        }
        public static DependencyItem[] GetSelectedDependsOn(this IDatabaseStructure db, DependencyItem selected, bool processReferences)
        {
            var res = new List <DependencyItem>();

            if (selected != null)
            {
                var obj = db.FindSpecificObject(selected.ObjectType, selected.Name);
                if (obj != null && obj.DependsOn != null)
                {
                    res.AddRange(obj.DependsOn);
                }
                if (processReferences && selected.ObjectType == "table")
                {
                    var tbl = db.FindTable(selected.Name);
                    if (tbl != null)
                    {
                        foreach (var fk in tbl.GetConstraints <IForeignKey>())
                        {
                            res.Add(new DependencyItem
                            {
                                Name       = fk.PrimaryKeyTable,
                                ObjectType = "table",
                            });
                        }
                    }
                }
            }
            return(res.ToArray());
        }
示例#12
0
 public override void WriteStructureAfterData(IDatabaseStructure db)
 {
     if (ProgressInfo != null)
     {
         ProgressInfo.SetCurWork("s_creating_references");
     }
     if (m_db.DatabaseCaps.ExecuteSql && !m_db.Dialect.DialectCaps.UncheckedReferences)
     {
         m_db.InvokeScript(dmp =>
         {
             foreach (var table in db.Tables)
             {
                 foreach (var cnt in table.GetConstraints <IForeignKey, IConstraint>())
                 {
                     try
                     {
                         dmp.CreateConstraint(cnt);
                     }
                     catch (Exception err)
                     {
                         ProgressInfo.LogMessageDetail("REFERENCE", LogLevel.Error, Texts.Get("s_error_creating_reference$fk", "fk", cnt.Name), err.ToString());
                     }
                 }
             }
         }, ProgressInfo);
     }
     //foreach (var table in m_dbStruct.Tables)
     //{
     //    var tdst = m_db.GetTable(table.FullName);
     //    tdst.CreateConstraints(table.GetConstraints<IForeignKey, IConstraint>());
     //}
 }
示例#13
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);
     //}
 }
        public static DependencyItem[] GetDependsOnSelected(this IDatabaseStructure db, DependencyItem selected, bool processReferences)
        {
            var res = new List <DependencyItem>();

            if (selected != null)
            {
                foreach (var spec in db.GetAllSpecificObjects())
                {
                    if (spec.DependsOn != null && spec.DependsOn.Contains(selected))
                    {
                        res.Add(new DependencyItem
                        {
                            Name       = spec.ObjectName,
                            ObjectType = spec.ObjectType,
                        });
                    }
                }
                if (processReferences && selected.ObjectType == "table")
                {
                    var tbl = db.FindTable(selected.Name);
                    if (tbl != null)
                    {
                        foreach (var fk in tbl.GetReferencedFrom())
                        {
                            res.Add(new DependencyItem
                            {
                                Name       = fk.Table.FullName,
                                ObjectType = "table",
                            });
                        }
                    }
                }
            }
            return(res.ToArray());
        }
示例#15
0
        public override void WriteStructureAfterData(IDatabaseStructure db)
        {
            var index_e = m_zip.PutNextEntry("_index_.xml");
            var dbcopy  = new DatabaseStructure(db);

            dbcopy.Save(m_zip);
        }
示例#16
0
        //public DbDefConnection(Func<string> getCurrentFileName)
        //    : base(null)
        //{
        //    m_getCurrentFileName = getCurrentFileName;
        //}

        //public DbDefConnection()
        //{
        //}

        public DbDefConnection(IDatabaseStructure db)
            : base(new DbDefStructureConnectionFactory {
            Structure = new DatabaseStructure(db)
        })
        {
            m_db = ((DbDefStructureConnectionFactory)PhysicalFactory).Structure;
        }
示例#17
0
        public override void WriteStructureBeforeData(IDatabaseStructure db)
        {
            using (StreamWriter sw = new StreamWriter(GetWorkingFileName()))
            {
                m_fmt.Writer   = sw;
                m_fmt.Language = Language;
                m_fmt.BeginFile("s_database");
                m_fmt.H2("s_tables");
                foreach (var tbl in db.Tables.SortedByKey <ITableStructure, NameWithSchema>(tbl => tbl.FullName))
                {
                    m_fmt.H3(String.Format("{0} {1}", Texts.LangGet("s_table", m_language), tbl));
                    m_fmt.BeginTable(new TableStyle {
                        Border = 1, WidthPercent = 100
                    });

                    m_fmt.BeginRow(true);
                    m_fmt.HeadingCell("s_name"); m_fmt.HeadingCell("s_type"); m_fmt.HeadingCell("s_nullable");
                    m_fmt.HeadingCell("s_default_value"); m_fmt.HeadingCell("s_keys");
                    m_fmt.EndRow(true);

                    foreach (var col in tbl.Columns)
                    {
                        m_fmt.BeginRow(false);
                        if (col.IsNullable)
                        {
                            m_fmt.Cell(col.ColumnName);
                        }
                        else
                        {
                            m_fmt.BeginCell(false).Bold(col.ColumnName).EndCell(false);
                        }
                        m_fmt.Cell(col.DataType);
                        m_fmt.Cell(col.IsNullable ? "s_yes" : "s_no");
                        m_fmt.Cell(col.DefaultValue.SafeGetSql(Dialect));

                        List <string> keys = new List <string>();
                        foreach (IPrimaryKey pk in tbl.GetConstraints <IPrimaryKey>())
                        {
                            if (pk.Columns.IndexOfIf(c => c.ColumnName == col.ColumnName) >= 0)
                            {
                                keys.Add("PK");
                            }
                        }
                        foreach (IForeignKey fk in tbl.GetConstraints <IForeignKey>())
                        {
                            if (fk.Columns.IndexOfIf(c => c.ColumnName == col.ColumnName) >= 0)
                            {
                                keys.Add("FK->" + fk.PrimaryKeyTable.ToString());
                            }
                        }
                        m_fmt.Cell(keys.CreateDelimitedText(", "));
                        m_fmt.EndRow(false);
                    }
                    m_fmt.EndTable();
                }
                m_fmt.EndFile();
                m_fmt.Writer = null;
            }
        }
示例#18
0
 public void CreateSpecificObjects(ISqlDumper dmp, IDatabaseStructure db)
 {
     dmp.CreateDatabaseObjects(db, new CreateDatabaseObjectsProps
     {
         AllFlags = false,
         CreateSpecificObjects = true,
     });
 }
 public static ISpecificObjectStructure FindSpecificObject(this IDatabaseStructure db, string objtype, NameWithSchema name)
 {
     if (!db.SpecificObjects.ContainsKey(objtype))
     {
         return(null);
     }
     return((ISpecificObjectStructure)(from i in db.SpecificObjects[objtype] where i.ObjectName == name select i).FirstOrDefault());
 }
示例#20
0
        public MySqlDatabaseEditor(IDatabaseStructure db, IDatabaseSource conn)
        {
            m_db   = db;
            m_conn = conn;

            Collation    = m_db.SpecificData.Get("mysql.collation");
            CharacterSet = m_db.SpecificData.Get("mysql.character_set");
        }
示例#21
0
        public static List <string> SchemaNames(Func <DatabaseStructureMembers, IDatabaseStructure> loadFunc)
        {
            DatabaseStructureMembers dbmem = new DatabaseStructureMembers {
                SchemaList = true
            };
            IDatabaseStructure dbs = loadFunc(dbmem);

            return(new List <string>(from s in dbs.Schemata select s.SchemaName));
        }
 public static IEnumerable <ISpecificObjectStructure> GetAllSpecificObjects(this IDatabaseStructure db)
 {
     foreach (string objtype in db.SpecificObjects.Keys)
     {
         foreach (SpecificObjectStructure spec in db.SpecificObjects[objtype])
         {
             yield return(spec);
         }
     }
 }
        public static ITableStructure FindSimilarTable(this IDatabaseStructure db, NameWithSchema name)
        {
            var res = db.FindTable(name);

            if (res != null)
            {
                return(res);
            }
            return((ITableStructure)(from t in db.Tables where t.FullName.Name.ToLower() == name.Name.ToLower() select t).FirstOrDefault());
        }
示例#24
0
        public DbDefViewTreeNode(IDatabaseStructure db, ISqlDialect dialect)
            : base("dbstruct")
        {
            m_db   = db;
            m_conn = new DbDefSource(m_db, DbDefSource.ReadOnly.Flag);
            var appobj = new DatabaseAppObject();

            appobj.FillFromDatabase(m_conn);
            SetAppObject(appobj);
            //m_commands = new DatabaseMenuCommands(m_conn, this);
        }
 public static IAbstractObjectStructure FindByGroupId(this IDatabaseStructure db, string groupid)
 {
     foreach (var obj in db.GetAllObjects())
     {
         if (obj.GroupId == groupid)
         {
             return(obj);
         }
     }
     return(null);
 }
示例#26
0
        public static IEnumerable <string> InvokeLoadCollations(this IDatabaseSource db)
        {
            IDatabaseStructure cat = db.InvokeLoadStructure(new DatabaseStructureMembers {
                CollationList = true
            }, null);

            foreach (var c in cat.Collations)
            {
                yield return(c.Name);
            }
        }
示例#27
0
        public static IEnumerable <string> InvokeLoadSchemata(this IDatabaseSource db)
        {
            IDatabaseStructure cat = db.InvokeLoadStructure(new DatabaseStructureMembers {
                SchemaList = true
            }, null);

            foreach (var s in cat.Schemata.Sorted())
            {
                yield return(s.SchemaName);
            }
        }
示例#28
0
        //public ITableSource CreateTable(ITableStructure table)
        //{
        //    Reload();
        //    ITableSource res = new TableDefSource(this, m_db.AddTable(MangleTable(table)));
        //    m_db.SortTables();
        //    SaveToFile();
        //    return res;
        //}

        public void AlterDatabase(IDatabaseStructure src, IDatabaseStructure dst, DbDiffOptions opts)
        {
            Reload();
            if (!SupportsMultipleSchema())
            {
                var tmp = new DatabaseStructure(dst);
                tmp.RunNameTransformation(new SetSchemaNameTransformation(null));
                dst = tmp;
            }
            m_conn.DbStruct.AlterDatabase(src, dst, opts, this);
            SaveToFile();
        }
示例#29
0
        public MergeSprocsService(
            ILogger <MergeSprocsService> logger,
            IDataAccess dataAccess,
            IScriptFactory scriptFactory,
            IDatabaseStructure databaseStructure)
        {
            this.logger = logger;

            _databaseStructure = databaseStructure;
            _dataAccess        = dataAccess;
            _scriptFactory     = scriptFactory;
        }
        public static ITableStructure InvokeLoadTableStructure(this IDatabaseSource conn, NameWithSchema name, TableStructureMembers members)
        {
            DatabaseStructureMembers dbmem = new DatabaseStructureMembers
            {
                TableFilter = new List <NameWithSchema> {
                    name
                },
                TableMembers = members
            };
            IDatabaseStructure dbs = conn.InvokeLoadStructure(dbmem, null);

            return(dbs.Tables[name]);
        }
		public virtual void Configure(IType type, IDictionary<string, string> parms, Dialect.Dialect dialect)
		{
			identifierType = type;
			bool forceTableUse = PropertiesHelper.GetBoolean(ForceTableParam, parms, false);

			string sequenceName = PropertiesHelper.GetString(SequenceParam, parms, DefaultSequenceName);
			if (sequenceName.IndexOf('.') < 0)
			{
				string schemaName;
				string catalogName;
				parms.TryGetValue(PersistentIdGeneratorParmsNames.Schema, out schemaName);
				parms.TryGetValue(PersistentIdGeneratorParmsNames.Catalog, out catalogName);
				sequenceName = Table.Qualify(catalogName, schemaName, sequenceName);
			}
			int initialValue = PropertiesHelper.GetInt32(InitialParam, parms, DefaultInitialValue);
			int incrementSize = PropertiesHelper.GetInt32(IncrementParam, parms, DefaultIncrementSize);

			string valueColumnName = PropertiesHelper.GetString(ValueColumnParam, parms, DefaultValueColumnName);

			string defOptStrategy = incrementSize <= 1 ? OptimizerFactory.None : OptimizerFactory.Pool;
			string optimizationStrategy = PropertiesHelper.GetString(OptimizerParam, parms, defOptStrategy);
			if (OptimizerFactory.None.Equals(optimizationStrategy) && incrementSize > 1)
			{
				log.Warn("config specified explicit optimizer of [" + OptimizerFactory.None + "], but [" + IncrementParam + "=" + incrementSize + "; honoring optimizer setting");
				incrementSize = 1;
			}
			if (dialect.SupportsSequences && !forceTableUse)
			{
				if (OptimizerFactory.Pool.Equals(optimizationStrategy) && !dialect.SupportsPooledSequences)
				{
					// TODO : may even be better to fall back to a pooled table strategy here so that the db stored values remain consistent...
					optimizationStrategy = OptimizerFactory.HiLo;
				}
				databaseStructure = new SequenceStructure(dialect, sequenceName, initialValue, incrementSize);
			}
			else
			{
				databaseStructure = new TableStructure(dialect, sequenceName, valueColumnName, initialValue, incrementSize);
			}

			optimizer = OptimizerFactory.BuildOptimizer(optimizationStrategy, identifierType.ReturnedClass, incrementSize);
			databaseStructure.Prepare(optimizer);
		}