Пример #1
0
        public IndexInfo CloneIndex(TableInfo ownTable = null)
        {
            var res = new IndexInfo(ownTable ?? OwnerTable);

            res.Assign(this);
            return(res);
        }
Пример #2
0
 public IndexInfo CloneIndex(TableInfo ownTable = null)
 {
     var res = new IndexInfo(ownTable ?? OwnerTable);
     res.Assign(this);
     return res;
 }
Пример #3
0
 public override void DropIndex(IndexInfo ix)
 {
     Put("^drop ^index %i ^on %f", ix.ConstraintName, ix.OwnerTable.FullName);
     EndCommand();
 }
Пример #4
0
 public override void CreateIndex(IndexInfo ix)
 {
     Put("^create");
     switch (ix.IndexType)
     {
         case DbIndexType.Fulltext:
             Put(" ^fulltext");
             break;
         case DbIndexType.Xml:
             Put(" ^xml");
             break;
         case DbIndexType.Spatial:
             Put(" ^spatial");
             break;
         case DbIndexType.Clustered:
             Put(" ^clustered");
             break;
     }
     if (ix.IsUnique) Put(" ^unique");
     Put(" ^index %i &n^on %f (&>&n", ix.ConstraintName, ix.OwnerTable.FullName);
     bool was = false;
     foreach (var col in ix.Columns.Where(x => !x.IsIncluded))
     {
         if (was) Put("&n,");
         Put("%i %k", col.RefColumnName, col.IsDescending ? "DESC" : "ASC");
         was = true;
     }
     Put("&<&n)");
     was = false;
     if (ix.Columns.Any(x => x.IsIncluded))
     {
         Put(" ^include (&>&n");
         foreach (var col in ix.Columns.Where(x => x.IsIncluded))
         {
             if (was) Put("&n,");
             Put("%i", col.RefColumnName);
             was = true;
         }
         Put("&<&n)");
     }
     EndCommand();
 }
Пример #5
0
 public virtual void CreateIndex(IndexInfo ix)
 {
     throw new NotImplementedException();
 }
Пример #6
0
 public void CreateIndex(IndexInfo ix)
 {
     _database.FindTable(ix.OwnerTable).AddConstraint(ix);
 }
Пример #7
0
 public void DropIndex(IndexInfo ix)
 {
     _database.FindTable(ix.OwnerTable).DropConstraint(ix);
 }
Пример #8
0
 public override void CreateIndex(IndexInfo ix)
 {
 }
Пример #9
0
        private void TestDiff(Action<DatabaseInfo> mangle, string expectedResult)
        {
            var db1 = new DatabaseInfo();
            var t1 = new TableInfo(db1)
                {
                    Name = "t1",
                    Schema = "dbo",
                };
            t1.Columns.Add(new ColumnInfo(t1)
                {
                    Name = "c1",
                    DataType = "int",
                    NotNull = true,
                    CommonType = new DbTypeInt(),
                });
            t1.Columns.Add(new ColumnInfo(t1)
                {
                    Name = "c2",
                    DataType = "int",
                    NotNull = true,
                    CommonType = new DbTypeInt(),
                });

            var ix = new IndexInfo(t1);
            ix.Columns.Add(new ColumnReference { RefColumn = t1.Columns[0] });
            ix.ConstraintName = "ix1";
            t1.Indexes.Add(ix);

            var pk = new PrimaryKeyInfo(t1);
            pk.Columns.Add(new ColumnReference {RefColumn = t1.Columns[0]});
            pk.ConstraintName = "pk_t1";
            t1.PrimaryKey = pk;

            db1.Tables.Add(t1);

            var v1 = new ViewInfo(db1)
                {
                    Name = "v1",
                    Schema = "dbo",
                    CreateSql = "create view v1 as select * from t1",
                };
            db1.Views.Add(v1);


            var db2 = db1.CloneDatabase();
            mangle(db2);
            var plan = new AlterPlan(db1);
            DbDiffTool.AlterDatabase(plan, db1, db2, new DbDiffOptions());
            var caps = SqlServerDatabaseFactory.Instance.DumperCaps;
            plan.AddLogicalDependencies(caps, new DbDiffOptions());
            plan.Transform(caps, new DbDiffOptions());

            var runner = plan.CreateRunner();
            var sw = new StringWriter();
            var sqlo = new SqlOutputStream(SqlServerDatabaseFactory.Instance.CreateDialect(), sw, new SqlFormatProperties());
            var dmp = SqlServerDatabaseFactory.Instance.CreateDumper(sqlo, new SqlFormatProperties());
            runner.Run(dmp, new DbDiffOptions());
            string sql = sw.ToString();
            Assert.IsNotNull(sql);
            //string expectedTran = TransformSql(expectedResult);
            //string sqlTran = TransformSql(sql);
            //for(int i = 0; i < expectedResult.Length; i++)
            //{
            //    Assert.AreEqual(expectedTran[i], sqlTran[i]);
            //}
            Assert.AreEqual(TransformSql(expectedResult), TransformSql(sql));
        }