コード例 #1
0
 public override string Generate(DeleteDefaultConstraintExpression expression)
 {
     truncator.Truncate(expression);
     return String.Format("ALTER TABLE {0} ALTER COLUMN {1} DROP DEFAULT",
         Quoter.QuoteTableName(expression.TableName),
         Quoter.QuoteColumnName(expression.ColumnName)
         );
 }
        public void ExecuteWithShouldDelegateProcessOnMigrationProcessor()
        {
            var expression = new DeleteDefaultConstraintExpression();
            var processorMock = new Mock<IMigrationProcessor>(MockBehavior.Strict);
            processorMock.Setup(p => p.Process(expression)).Verifiable();

            expression.ExecuteWith(processorMock.Object);

            processorMock.VerifyAll();
        }
コード例 #3
0
        public void CanGenerateNecessaryStatementsForADeleteDefaultExpression()
        {
            var expression = new DeleteDefaultConstraintExpression {ColumnName = "Name", SchemaName = "Personalia", TableName = "Person"};

            const string expected = "DECLARE @default sysname, @sql nvarchar(max);\r\n\r\n" +
                                    "-- get name of default constraint\r\n" +
                                    "SELECT @default = name\r\n" +
                                    "FROM sys.default_constraints\r\n" +
                                    "WHERE parent_object_id = object_id('[Personalia].[Person]')\r\n" + "" +
                                    "AND type = 'D'\r\n" + "" +
                                    "AND parent_column_id = (\r\n" + "" +
                                    "SELECT column_id\r\n" +
                                    "FROM sys.columns\r\n" +
                                    "WHERE object_id = object_id('[Personalia].[Person]')\r\n" +
                                    "AND name = 'Name'\r\n" +
                                    ");\r\n\r\n" +
                                    "-- create alter table command to drop contraint as string and run it\r\n" +
                                    "SET @sql = N'ALTER TABLE [Personalia].[Person] DROP CONSTRAINT ' + @default;\r\n" +
                                    "EXEC sp_executesql @sql;";

            generator.Generate(expression).ShouldBe(expected);
        }
コード例 #4
0
 public override string Generate(DeleteDefaultConstraintExpression expression)
 {
     string sql =
         "DECLARE @default sysname, @sql nvarchar(max);" + Environment.NewLine + Environment.NewLine +
         "-- get name of default constraint" + Environment.NewLine +
         "SELECT @default = name" + Environment.NewLine +
         "FROM sys.default_constraints" + Environment.NewLine +
         "WHERE parent_object_id = object_id('{2}.{0}')" + Environment.NewLine +
         "AND type = 'D'" + Environment.NewLine +
         "AND parent_column_id = (" + Environment.NewLine +
         "SELECT column_id" + Environment.NewLine +
         "FROM sys.columns" + Environment.NewLine +
         "WHERE object_id = object_id('{2}.{0}')" + Environment.NewLine +
         "AND name = '{1}'" + Environment.NewLine +
         ");" + Environment.NewLine + Environment.NewLine +
         "-- create alter table command to drop constraint as string and run it" + Environment.NewLine +
         "SET @sql = N'ALTER TABLE {2}.{0} DROP CONSTRAINT ' + @default;" + Environment.NewLine +
         "EXEC sp_executesql @sql;";
     return String.Format(sql, Quoter.QuoteTableName(expression.TableName), expression.ColumnName, Quoter.QuoteSchemaName(expression.SchemaName));
 }
コード例 #5
0
 public virtual void Process(DeleteDefaultConstraintExpression expression)
 {
     Process(Generator.Generate(expression));
 }
コード例 #6
0
 public override string Generate(DeleteDefaultConstraintExpression expression)
 {
     return Generate(new AlterDefaultConstraintExpression
     {
         TableName = expression.TableName,
         ColumnName = expression.ColumnName,
         DefaultValue = null
     });
 }
コード例 #7
0
 public override string Generate(DeleteDefaultConstraintExpression expression)
 {
     return compatabilityMode.HandleCompatabilty("Default constraints are not supported");
 }
コード例 #8
0
 public override string Generate(DeleteDefaultConstraintExpression expression)
 {
     return string.Format("ALTER TABLE {0}.{1} ALTER {2} DROP DEFAULT", Quoter.QuoteSchemaName(expression.SchemaName), Quoter.QuoteTableName(expression.TableName), Quoter.Quote(expression.ColumnName));
 }
コード例 #9
0
 public void Truncate(DeleteDefaultConstraintExpression expression)
 {
     expression.TableName = Truncate(expression.TableName);
     expression.ColumnName = Truncate(expression.ColumnName);
 }
        public void ToStringIsDescriptive()
        {
            var expression = new DeleteDefaultConstraintExpression {SchemaName = "ThaSchema", TableName = "ThaTable", ColumnName = "ThaColumn"};

            expression.ToString().ShouldBe("DeleteDefaultConstraint ThaSchema.ThaTable ThaColumn");
        }
 public void CollectValidationErrorsShouldReturnErrorIfTableNameIsNull()
 {
     var expression = new DeleteDefaultConstraintExpression {TableName = null};
     var errors = ValidationHelper.CollectErrors(expression);
     errors.ShouldContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
 }
 public void CollectValidationErrorsShouldReturnErrorIfColumnNameIsEmpty()
 {
     var expression = new DeleteDefaultConstraintExpression {ColumnName = string.Empty};
     var errors = ValidationHelper.CollectErrors(expression);
     errors.ShouldContain(ErrorMessages.ColumnNameCannotBeNullOrEmpty);
 }
コード例 #13
0
        public void GenerateNecessaryStatementsForADeleteDefaultExpressionIsThrowsException()
        {
            var expression = new DeleteDefaultConstraintExpression { ColumnName = "Name", SchemaName = "Personalia", TableName = "Person" };

            Assert.Throws<DatabaseOperationNotSupportedException>(() => Generator.Generate(expression));
        }
 public void Setup()
 {
     expression = new DeleteDefaultConstraintExpression();
     builder = new DeleteDefaultConstraintExpressionBuilder(expression);
 }
コード例 #15
0
 public IDeleteDefaultConstraintOnTableSyntax DefaultConstraint()
 {
     var expression = new DeleteDefaultConstraintExpression();
     _context.Expressions.Add(expression);
     return new DeleteDefaultConstraintExpressionBuilder(expression);
 }
コード例 #16
0
        public void CanGenerateNecessaryStatementsForADeleteDefaultExpression()
        {
            var expression = new DeleteDefaultConstraintExpression {ColumnName = "Name", SchemaName = "Personalia", TableName = "Person"};

            var expected = "DECLARE @default sysname, @sql nvarchar(4000);" + Environment.NewLine + Environment.NewLine +
                                    "-- get name of default constraint" + Environment.NewLine +
                                    "SELECT @default = name" + Environment.NewLine +
                                    "FROM sys.default_constraints" + Environment.NewLine +
                                    "WHERE parent_object_id = object_id('[Person]')" + Environment.NewLine +
                                    "AND type = 'D'" + Environment.NewLine +
                                    "AND parent_column_id = (" + Environment.NewLine +
                                    "SELECT column_id" + Environment.NewLine +
                                    "FROM sys.columns" + Environment.NewLine +
                                    "WHERE object_id = object_id('[Person]')" + Environment.NewLine +
                                    "AND name = 'Name'" + Environment.NewLine +
                                    ");" + Environment.NewLine + Environment.NewLine +
                                    "-- create alter table command to drop constraint as string and run it" + Environment.NewLine +
                                    "SET @sql = N'ALTER TABLE [Person] DROP CONSTRAINT ' + @default;" + Environment.NewLine +
                                    "EXEC sp_executesql @sql;";

            var result = Generator.Generate(expression);
            result.ShouldBe(expected);
        }
コード例 #17
0
 public abstract string Generate(DeleteDefaultConstraintExpression expression);
コード例 #18
0
 public void GenerateNecessaryStatementsForADeleteDefaultExpressionIsThrowsException()
 {
     var expression = new DeleteDefaultConstraintExpression {ColumnName = "Name", SchemaName = "Personalia", TableName = "Person"};
     generator.Generate(expression);
 }
コード例 #19
0
        public override string Generate(DeleteDefaultConstraintExpression expression)
        {
            const string sql =
                "DECLARE @default sysname, @sql nvarchar(4000);\r\n\r\n" +
                "-- get name of default constraint\r\n" +
                "SELECT @default = name\r\n" +
                "FROM sys.default_constraints\r\n" +
                "WHERE parent_object_id = object_id('{0}')\r\n" + "" +
                "AND type = 'D'\r\n" + "" +
                "AND parent_column_id = (\r\n" + "" +
                "SELECT column_id\r\n" +
                "FROM sys.columns\r\n" +
                "WHERE object_id = object_id('{0}')\r\n" +
                "AND name = '{1}'\r\n" +
                ");\r\n\r\n" +
                "-- create alter table command to drop contraint as string and run it\r\n" +
                "SET @sql = N'ALTER TABLE {0} DROP CONSTRAINT ' + @default;\r\n" +
                "EXEC sp_executesql @sql;";

            return String.Format(sql, Quoter.QuoteTableName(expression.TableName), expression.ColumnName);
        }
コード例 #20
0
 public override string Generate(DeleteDefaultConstraintExpression expression)
 {
     throw new DatabaseOperationNotSupportedException();
 }
コード例 #21
0
        public void CanDeleteDefaultConstraint()
        {
            var expression = new DeleteDefaultConstraintExpression
            {
                ColumnName = "TestColumn1",
                SchemaName = "TestSchema",
                TableName = "TestTable1"
            };

            var result = Generator.Generate(expression);
            result.ShouldBe("ALTER TABLE \"TestSchema\".\"TestTable1\" ALTER \"TestColumn1\" DROP DEFAULT");
        }
コード例 #22
0
 public static DeleteDefaultConstraintExpression GetDeleteDefaultConstraintExpression()
 {
     var expression = new DeleteDefaultConstraintExpression
     {
         ColumnName = TestColumnName1,
         TableName = TestTableName1
     };
     return expression;
 }
コード例 #23
0
 public override string Generate(DeleteDefaultConstraintExpression expression)
 {
     throw new NotImplementedException();
 }
コード例 #24
0
        public void CanDeleteDefaultConstraint()
        {
            Assert.Ignore("Hana support change default value with type like bellow");
            
            var expression = new DeleteDefaultConstraintExpression
            {
                ColumnName = "TestColumn1",
                SchemaName = "TestSchema",
                TableName = "TestTable1"
            };

            var result = Generator.Generate(expression);
            result.ShouldBe("ALTER TABLE \"TestTable1\" ALTER (\"TestColumn1\" NVARCHAR(255) DEFAULT NULL)");
        }