public void Visit(StringBuilder builder, AlterColumnCommand command)
        {
            if (ExecuteCustomInterpreter(command))
            {
                return;
            }

            builder.AppendFormat("alter table {0} alter column {1} ",
                                 _dialect.QuoteForTableName(PrefixTableName(command.TableName)),
                                 _dialect.QuoteForColumnName(command.ColumnName));

            // type
            if (command.DbType != DbType.Object)
            {
                builder.Append(GetTypeName(_dialect, command.DbType, command.Length, command.Precision, command.Scale));
            }
            else
            {
                if (command.Length > 0 || command.Precision > 0 || command.Scale > 0)
                {
                    throw new OrchardException(T("Error while executing data migration: you need to specify the field's type in order to change its properties"));
                }
            }

            // [default value]
            if (command.Default != null)
            {
                builder.Append(" set default ").Append(ConvertToSqlValue(command.Default)).Append(Space);
            }
            _sqlStatements.Add(builder.ToString());
        }
Beispiel #2
0
        public virtual void Run(StringBuilder builder, AlterColumnCommand command)
        {
            builder.AppendFormat("alter table {0} alter column {1} ",
                                 _dialect.QuoteForTableName(command.TableName),
                                 _dialect.QuoteForColumnName(command.ColumnName));

            // type
            if (command.DbType != DbType.Object)
            {
                builder.Append(_dialect.GetTypeName(command.DbType, command.Length, command.Precision, command.Scale));
            }
            else
            {
                if (command.Length > 0 || command.Precision > 0 || command.Scale > 0)
                {
                    throw new Exception("Error while executing data migration: you need to specify the field's type in order to change its properties");
                }
            }

            // [default value]
            if (command.Default != null)
            {
                builder.Append(" set default ").Append(_dialect.GetSqlValue(command.Default)).Append(Space);
            }
        }
        protected override IExistingColumn CreateItem(string name)
        {
            var command = new AlterColumnCommand(_command, name);

            _command.Add(command);
            return(new ExistingColumn(command));
        }
Beispiel #4
0
        public override void Run(StringBuilder builder, AlterColumnCommand command)
        {
            builder.AppendFormat("alter table {0} modify column {1} ",
                                 _dialect.QuoteForTableName(command.TableName),
                                 _dialect.QuoteForColumnName(command.ColumnName));
            var initLength = builder.Length;

            // type
            if (command.DbType != DbType.Object)
            {
                builder.Append(_dialect.GetTypeName(command.DbType, command.Length, command.Precision, command.Scale));
            }
            else
            {
                if (command.Length > 0 || command.Precision > 0 || command.Scale > 0)
                {
                    throw new Exception("Error while executing data migration: you need to specify the field's type in order to change its properties");
                }
            }

            // [default value]
            var builder2 = new StringBuilder();

            builder2.AppendFormat("alter table {0} alter column {1} ",
                                  _dialect.QuoteForTableName(command.TableName),
                                  _dialect.QuoteForColumnName(command.ColumnName));
            var initLength2 = builder2.Length;

            if (command.Default != null)
            {
                builder2.Append(" set default ").Append(_dialect.GetSqlValue(command.Default)).Append(" ");
            }

            // result
            var result = new List <string>();

            if (builder.Length > initLength)
            {
                result.Add(builder.ToString());
            }

            if (builder2.Length > initLength2)
            {
                result.Add(builder2.ToString());
            }
        }
        public string[] CreateStatements(AlterColumnCommand command)
        {
            var statements = new List <string>();
            var builder    = new StringBuilder();

            builder.AppendFormat("alter table {0} alter column {1} ",
                                 _dialect.QuoteForTableName(PrefixTableName(command.TableName)),
                                 _dialect.QuoteForColumnName(command.ColumnName));

            // type
            if (command.DbType != DbType.Object)
            {
                builder.Append(GetTypeName(command.DbType, command.Length, command.Precision, command.Scale));
            }
            else
            {
                if (command.Length > 0 || command.Precision > 0 || command.Scale > 0)
                {
                    throw new MonahrqCoreException("Error while executing data migration: you need to specify the field's type in order to change it's properies");
                }
            }

            statements.Add(builder.ToString());

            // [default value]
            if (command.Default != null)
            {
                statements.Add(
                    string.Format(" alter table {0} add constraint [D_{1}] default {2} for {3} ",
                                  _dialect.QuoteForTableName(PrefixTableName(command.TableName)),
                                  Guid.NewGuid().ToString("N").Substring(0, 8),
                                  ConvertToSqlValue(command.Default),
                                  _dialect.QuoteForColumnName(command.ColumnName)
                                  )
                    );
            }
            return(statements.ToArray());
        }
 public string[] CreateStatements(AlterColumnCommand command)
 {
     return(new string[0]);
 }
Beispiel #7
0
 internal ExistingColumn(AlterColumnCommand command)
 {
     _command = command;
 }