public void CanAlterColumn()
 {
     var expression = new AlterColumnExpression
                          {
                              Column = new ColumnDefinition { Type = DbType.String, Name = "Col1" },
                              SchemaName = "Schema1",
                              TableName = "Table1"
                          };
     var sql = generator.Generate(expression);
     sql.ShouldBe(String.Empty);
 }
 public override string Generate(AlterColumnExpression expression)
 {
     var alterStatement = new StringBuilder();
     alterStatement.Append(String.Format("ALTER TABLE {0}.{1} {2}", Quoter.QuoteSchemaName(expression.SchemaName), Quoter.QuoteTableName(expression.TableName), ((PostgresColumn)Column).GenerateAlterClauses(expression.Column)));
     var descriptionStatement = DescriptionGenerator.GenerateDescriptionStatement(expression);
     if (!string.IsNullOrEmpty(descriptionStatement))
     {
         alterStatement.Append(";");
         alterStatement.Append(descriptionStatement);
     }
     return alterStatement.ToString();
 }
        public static AlterColumnExpression GetAlterColumnExpression()
        {
            var expression = new AlterColumnExpression();
            expression.TableName = TestTableName1;

            expression.Column = new ColumnDefinition();
            expression.Column.Name = TestColumnName1;
            expression.Column.Type = DbType.String;
            expression.Column.Size = 20;
            expression.Column.IsNullable = false;

            return expression;
        }
        public override string GenerateDescriptionStatement(AlterColumnExpression expression)
        {
            if (string.IsNullOrEmpty(expression.Column.ColumnDescription))
                return string.Empty;

            var formattedSchemaName = FormatSchemaName(expression.SchemaName);

            // For this, we need to remove the extended property first if exists (or implement verification and use sp_updateextendedproperty)
            var columnVerificationStatement = string.Format(ColumnDescriptionVerificationTemplate, formattedSchemaName, expression.TableName, expression.Column.Name);
            var removalStatement = string.Format("{0} {1}", columnVerificationStatement, GenerateColumnDescriptionRemoval(formattedSchemaName, expression.TableName, expression.Column.Name));
            var newDescriptionStatement = GenerateColumnDescription(formattedSchemaName, expression.TableName, expression.Column.Name, expression.Column.ColumnDescription);

            return string.Join(";", new[] { removalStatement, newDescriptionStatement });
        }
        public override void Process(AlterColumnExpression expression)
        {
            var tableDefinition = GetTableSchema(expression.TableName);

            var columnDefinitions = tableDefinition.Columns.ToList();
            var columnIndex = columnDefinitions.FindIndex(c => c.Name == expression.Column.Name);

            if (columnIndex == -1)
            {
                throw new ApplicationException(string.Format("Column {0} does not exist on table {1}.", expression.Column.Name, expression.TableName));
            }

            columnDefinitions[columnIndex] = expression.Column;

            tableDefinition.Columns = columnDefinitions;

            ProcessAlterTable(tableDefinition);
        }
 public virtual void Process(AlterColumnExpression expression)
 {
     Process(Generator.Generate(expression));
 }
 public override string Generate(AlterColumnExpression expression)
 {
     return string.Format("ALTER TABLE {0}", base.Generate(expression));
 }
 public void Truncate(AlterColumnExpression expression)
 {
     expression.TableName = Truncate(expression.TableName);
     Truncate(expression.Column);
 }
 public void CanAlterColumn()
 {
     var expression = new AlterColumnExpression
                          {
                              Column = new ColumnDefinition {Type = DbType.String, Name = "Col1"},
                              SchemaName = "Schema1",
                              TableName = "Table1"
                          };
     var sql = generator.Generate(expression);
     sql.ShouldBe("ALTER TABLE \"Schema1\".\"Table1\" ALTER \"Col1\" TYPE text");
 }
 public void ToStringIsDescriptive()
 {
     var expression = new AlterColumnExpression { TableName = "Bacon", Column = { Name = "BaconId", Type = DbType.Int32 } };
     expression.ToString().ShouldBe("AlterColumn Bacon BaconId Int32");
 }
        public override string Generate(AlterColumnExpression expression)
        {
            var descriptionStatement = DescriptionGenerator.GenerateDescriptionStatement(expression);

            if (string.IsNullOrEmpty(descriptionStatement))
                return base.Generate(expression);

            var wrappedAlterColumnStatement = WrapStatementInExecuteImmediateBlock(base.Generate(expression));

            var alterColumnWithDescriptionBuilder = new StringBuilder(wrappedAlterColumnStatement);
            alterColumnWithDescriptionBuilder.Append(WrapStatementInExecuteImmediateBlock(descriptionStatement));

            return WrapInBlock(alterColumnWithDescriptionBuilder.ToString());
        }
 public override string Generate(AlterColumnExpression expression)
 {
     throw new NotImplementedException();
 }
        public void CanAlterColumnAndSetAsNullable()
        {
            var expression = new AlterColumnExpression
            {
                Column = new ColumnDefinition { Type = DbType.String, Name = "TestColumn1", IsNullable = true },
                SchemaName = "TestSchema",
                TableName = "TestTable1"
            };

            var result = Generator.Generate(expression);
            result.ShouldBe("ALTER TABLE \"TestSchema\".\"TestTable1\" ALTER \"TestColumn1\" TYPE text, ALTER \"TestColumn1\" DROP NOT NULL");
        }
 public override string Generate(AlterColumnExpression expression)
 {
     return compatabilityMode.HandleCompatabilty("Sqlite does not support alter column");
 }
        public void CanAlterColumnAndSetAsNullable()
        {
            var expression = new AlterColumnExpression
            {
                Column = new ColumnDefinition { Type = DbType.String, Name = "TestColumn1", IsNullable = true },
                SchemaName = "TestSchema",
                TableName = "TestTable1"
            };

            var result = Generator.Generate(expression);
            result.ShouldBe("ALTER TABLE TestSchema.TestTable1 ALTER COLUMN TestColumn1 SET DATA TYPE DBCLOB(1048576) CCSID 1200");
        }
 public string GenerateDescriptionStatement(AlterColumnExpression expression)
 {
     return string.Empty;
 }
        public void CanAlterColumn()
        {
            var expression = new AlterColumnExpression();
            expression.TableName = "Table1";

            expression.Column = new ColumnDefinition();
            expression.Column.Name = "Column1";
            expression.Column.Type = DbType.String;
            expression.Column.Size = 20;
            expression.Column.IsNullable = false;

            var sql = generator.Generate(expression);
            sql.ShouldBe("ALTER TABLE [Table1] ALTER COLUMN [Column1] VARCHAR(20) NOT NULL");
        }
 public override string Generate(AlterColumnExpression expression)
 {
     return String.Format("ALTER TABLE {0}[{1}] ALTER COLUMN {2}", FormatSchema(expression.SchemaName), expression.TableName, Column.Generate(expression.Column));
 }
 public IAlterColumnOnTableSyntax Column(string columnName)
 {
     var expression = new AlterColumnExpression { Column = { Name = columnName } };
     _context.Expressions.Add(expression);
     return new AlterColumnExpressionBuilder(expression, _context);
 }
 public override string Generate(AlterColumnExpression expression)
 {
     return String.Format("ALTER TABLE {0} MODIFY {1}", expression.TableName, Column.Generate(expression.Column));
 }
 public override string Generate(AlterColumnExpression expression)
 {
     return String.Format("ALTER TABLE {0}.{1} {2}", Quoter.QuoteSchemaName(expression.SchemaName), Quoter.QuoteTableName(expression.TableName), ((PostgresColumn)Column).GenerateAlterClauses(expression.Column));
 }
 public void ErrorIsNotReturnedWhenOldNameIsNotNullEmptyString()
 {
     var expression = new AlterColumnExpression { TableName = "Bacon" };
     var errors = ValidationHelper.CollectErrors(expression);
     errors.ShouldNotContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
 }
        public void CanAlterColumnAndOnlySetTypeIfIsNullableNotSet()
        {
            var expression = new AlterColumnExpression
            {
                Column = new ColumnDefinition { Type = DbType.String, Name = "TestColumn1", IsNullable = null },
                SchemaName = "TestSchema",
                TableName = "TestTable1"
            };

            var result = Generator.Generate(expression);
            result.ShouldBe("ALTER TABLE \"TestSchema\".\"TestTable1\" ALTER \"TestColumn1\" TYPE text");
        }
        public override string Generate(AlterColumnExpression expression)
        {
            var alterTableStatement = string.Format("ALTER TABLE {0}.{1}", Quoter.QuoteSchemaName(expression.SchemaName), base.Generate(expression));
            var descriptionStatement = DescriptionGenerator.GenerateDescriptionStatement(expression);

            if (string.IsNullOrEmpty(descriptionStatement))
                return alterTableStatement;

            return ComposeStatements(alterTableStatement, new[] { descriptionStatement });
        }
 public override string Generate(AlterColumnExpression expression)
 {
     return String.Format(AlterColumn, Quoter.QuoteTableName(expression.TableName), Column.Generate(expression.Column));
 }
 public override string Generate(AlterColumnExpression expression)
 {
     return string.Format("ALTER TABLE {0}.{1}", Quoter.QuoteSchemaName(expression.SchemaName), base.Generate(expression));
 }
        public override string Generate(AlterColumnExpression expression)
        {
            string errors = ValidateAdditionalFeatureCompatibility(expression.Column.AdditionalFeatures);
            if (!string.IsNullOrEmpty(errors)) return errors;

            return String.Format(AlterColumn, Quoter.QuoteTableName(expression.TableName), Column.Generate(expression.Column));
        }
 public override string Generate(AlterColumnExpression expression)
 {
     return String.Format("ALTER TABLE {0}.{1} ALTER {2} TYPE {3}", Quoter.QuoteSchemaName(expression.SchemaName), Quoter.QuoteTableName(expression.TableName), Quoter.QuoteColumnName(expression.Column.Name), ((PostgresColumn)Column).GetColumnType(expression.Column));
 }
 public override string Generate(AlterColumnExpression expression)
 {
     truncator.Truncate(expression);
     return compatabilityMode.HandleCompatabilty("Alter column is not supported as expected");
 }
Beispiel #30
0
 public abstract string Generate(AlterColumnExpression expression);