public void ChangeViewSchema(ViewInfo obj, string newschema)
 {
     var oldObj = _database.FindView(obj);
     if (oldObj != null)
     {
         oldObj.FullName = new NameWithSchema(newschema, oldObj.FullName.Name);
     }
 }
 public void RenameView(ViewInfo obj, string newname)
 {
     var oldObj = _database.FindView(obj);
     if (oldObj != null)
     {
         oldObj.FullName = new NameWithSchema(oldObj.FullName.Schema, newname);
     }
 }
 public void AlterView(ViewInfo obj)
 {
     var oldObj = _database.FindView(obj);
     if (oldObj != null)
     {
         string gid = oldObj.GroupId;
         oldObj.Assign(obj);
         oldObj.GroupId = gid;
     }
 }
Exemple #4
0
        public override void AfterLoadLink()
        {
            base.AfterLoadLink();

            if (RelatedTable == null)
            {
                RelatedTable = OwnerDatabase.GetTable(new NameWithSchema(_tableOrViewSchema, _tableOrViewName));
            }
            if (RelatedView == null)
            {
                RelatedView = OwnerDatabase.GetView(new NameWithSchema(_tableOrViewSchema, _tableOrViewName));
            }
            _tableOrViewName = null;
            _tableOrViewSchema = null;
        }
 public override void ChangeViewSchema(ViewInfo obj, string newschema)
 {
     ChangeObjectSchema(obj, newschema);
 }
 public override void RenameView(ViewInfo obj, string newname)
 {
     RenameObject(obj, newname);
 }
Exemple #7
0
 public virtual void RenameView(ViewInfo obj, string newname)
 {
     throw new System.NotImplementedException();
 }
Exemple #8
0
 public virtual void ChangeViewSchema(ViewInfo obj, string newschema)
 {
     throw new System.NotImplementedException();
 }
Exemple #9
0
 public virtual void AlterView(ViewInfo obj)
 {
     WriteRaw(Regex.Replace(obj.CreateSql, @"create\s+view", "ALTER VIEW", RegexOptions.IgnoreCase));
     EndCommand();
 }
Exemple #10
0
 public virtual void DropView(ViewInfo obj, bool testIfExists)
 {
     PutCmd("^drop ^view  %f", obj.FullName);
 }
Exemple #11
0
 public virtual void CreateView(ViewInfo obj)
 {
     WriteRaw(obj.CreateSql);
     EndCommand();
 }
 public void DropView(ViewInfo obj, bool testIfExists)
 {
     _database.Views.RemoveAll(v => v.FullName == obj.FullName);
 }
 public void CreateView(ViewInfo obj)
 {
     _database.Views.Add(obj.CloneView(_database));
 }
Exemple #14
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));
        }
Exemple #15
0
 public ViewInfo CloneView(DatabaseInfo ownerDb = null)
 {
     var res = new ViewInfo(ownerDb ?? OwnerDatabase);
     res.Assign(this);
     return res;
 }