public void Generate_should_throw_when_column_rename()
        {
            var migrationProvider = new SqlCeMigrationSqlGenerator();

            var renameColumnOperation = new RenameColumnOperation("T", "c", "c'");

            Assert.Equal(Strings.SqlCeColumnRenameNotSupported, Assert.Throws<MigrationsException>(() => migrationProvider.Generate(new[] { renameColumnOperation }, "4.0").ToList()).Message);
        }
        public void Can_get_and_set_rename_properties()
        {
            var renameColumnOperation = new RenameColumnOperation("T", "N", "N'");

            Assert.Equal("T", renameColumnOperation.Table);
            Assert.Equal("N", renameColumnOperation.Name);
            Assert.Equal("N'", renameColumnOperation.NewName);
        }
        public void Can_get_and_set_rename_properties()
        {
            var renameColumnOperation = new RenameColumnOperation("T", "N", "N'");

            Assert.Equal("T", renameColumnOperation.Table);
            Assert.Equal("N", renameColumnOperation.Name);
            Assert.Equal("N'", renameColumnOperation.NewName);
        }
        public void Inverse_should_produce_rename_column_operation()
        {
            var renameColumnOperation = new RenameColumnOperation("T", "N", "N'");

            var inverse = (RenameColumnOperation)renameColumnOperation.Inverse;

            Assert.Equal("T", inverse.Table);
            Assert.Equal("N'", inverse.Name);
            Assert.Equal("N", inverse.NewName);
        }
        public void Inverse_should_produce_rename_column_operation()
        {
            var renameColumnOperation
                = new RenameColumnOperation("T", "N", "N'");

            var inverse = (RenameColumnOperation)renameColumnOperation.Inverse;

            Assert.Equal("T", inverse.Table);
            Assert.Equal("N'", inverse.Name);
            Assert.Equal("N", inverse.NewName);
        }
 protected virtual IEnumerable<MigrationStatement> Generate(RenameColumnOperation operation)
 {
     using (var writer = SqlWriter())
     {
         writer.Write("ALTER TABLE ");
         writer.Write(Quote(operation.Table));
         writer.Write(" RENAME COLUMN ");
         writer.Write(Quote(operation.Name));
         writer.Write(" TO ");
         writer.Write(Quote(operation.NewName));
         yield return Statement(writer);
     }
 }
        protected virtual MigrationStatement Generate(RenameColumnOperation op)
        {
            if (op == null) return null;

              StringBuilder sb = new StringBuilder();

              sb.Append("set @columnType := (select case lower(IS_NULLABLE) when `no` then CONCAT(column_type, ` ` , `not null `)  when `yes` then column_type end from information_schema.columns where table_name = `" + op.Table + "` and column_name = `" + op.Name + "` );");
              sb.AppendLine();
              sb.Append("set @sqlstmt := (select concat(`alter table " + op.Table + " change `" + op.Name + "` " + op.NewName + "` , @columnType));");
              sb.AppendLine();
              sb.Append("prepare stmt @sqlstmt;");
              sb.AppendLine();
              sb.Append("execute stmt;");
              sb.AppendLine();
              sb.Append("deallocate prepare stmt");
              return new MigrationStatement { Sql = sb.ToString() };
        }
 protected override void Generate(RenameColumnOperation renameColumnOperation, IndentedTextWriter writer)
 {
     var rename = new RenameColumnOperation(TrimSchemaPrefix(renameColumnOperation.Table), renameColumnOperation.Name, renameColumnOperation.NewName);
       base.Generate(rename, writer);
 }
        /// <summary>
        /// Generates code to perform a <see cref="RenameColumnOperation" />.
        /// </summary>
        /// <param name="renameColumnOperation"> The operation to generate code for. </param>
        /// <param name="writer"> Text writer to add the generated code to. </param>
        protected virtual void Generate(RenameColumnOperation renameColumnOperation, IndentedTextWriter writer)
        {
            Check.NotNull(renameColumnOperation, "renameColumnOperation");
            Check.NotNull(writer, "writer");

            writer.Write("RenameColumn(table := ");
            writer.Write(Quote(renameColumnOperation.Table));
            writer.Write(", name := ");
            writer.Write(Quote(renameColumnOperation.Name));
            writer.Write(", newName := ");
            writer.Write(Quote(renameColumnOperation.NewName));
            writer.WriteLine(")");
        }
        /// <summary>
        /// Generates SQL for a <see cref="RenameColumnOperation" />.
        /// Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name="renameColumnOperation"> The operation to produce SQL for. </param>
        protected virtual void Generate(RenameColumnOperation renameColumnOperation)
        {
            Check.NotNull(renameColumnOperation, "renameColumnOperation");

            using (var writer = Writer())
            {
                writer.Write("EXECUTE sp_rename @objname = N'");
                writer.Write(Escape(renameColumnOperation.Table));
                writer.Write(".");
                writer.Write(Escape(renameColumnOperation.Name));
                writer.Write("', @newname = N'");
                writer.Write(Escape(renameColumnOperation.NewName));
                writer.Write("', @objtype = N'COLUMN'");

                Statement(writer);
            }
        }
 private void Convert(RenameColumnOperation renameColumnOperation)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("ALTER TABLE ");
     AppendTableName(renameColumnOperation.Table, sql);
     sql.Append(" RENAME COLUMN \"");
     sql.Append(renameColumnOperation.Name);
     sql.Append("\" TO \"");
     sql.Append(renameColumnOperation.NewName);
     sql.Append('"');
     AddStatment(sql);
 }
    protected virtual MigrationStatement Generate(RenameColumnOperation op)
    {
      if (op == null) return null;

      StringBuilder sb = new StringBuilder();

      sb.Append("set @columnType := (select case lower(IS_NULLABLE) when 'no' then CONCAT(column_type, ' not null ')  when 'yes' then column_type end from information_schema.columns where table_name = '" + TrimSchemaPrefix(op.Table) + "' and column_name = '" + op.Name + "');");
      sb.AppendLine();
      sb.Append("set @sqlstmt := (select concat('alter table `" + TrimSchemaPrefix(op.Table) + "` change `" + op.Name + "` `" + op.NewName + "` ' , @columnType));");
      sb.AppendLine();
      sb.Append("prepare stmt from @sqlstmt;");
      sb.AppendLine();
      sb.Append("execute stmt;");
      sb.AppendLine();
      sb.Append("deallocate prepare stmt;");
      return new MigrationStatement { Sql = sb.ToString() };

    }
        /// <summary>
        ///     Generates code to perform a <see cref = "RenameColumnOperation" />.
        /// </summary>
        /// <param name = "renameColumnOperation">The operation to generate code for.</param>
        /// <param name = "writer">Text writer to add the generated code to.</param>
        protected virtual void Generate(RenameColumnOperation renameColumnOperation, IndentedTextWriter writer)
        {
            Contract.Requires(renameColumnOperation != null);
            Contract.Requires(writer != null);

            writer.Write("RenameColumn(table := ");
            writer.Write(Quote(renameColumnOperation.Table));
            writer.Write(", name := ");
            writer.Write(Quote(renameColumnOperation.Name));
            writer.Write(", newName := ");
            writer.Write(Quote(renameColumnOperation.NewName));
            writer.WriteLine(")");
        }
 /// <summary>
 ///     Generates SQL for a <see cref="RenameColumnOperation" />.
 ///     Generated SQL should be added using the Statement method.
 /// </summary>
 /// <param name="renameColumnOperation"> The operation to produce SQL for. </param>
 protected virtual void Generate(RenameColumnOperation renameColumnOperation)
 {
     throw Error.SqlCeColumnRenameNotSupported();
 }
 /// <summary>
 /// Gera SQL para uma operação <see cref="RenameColumnOperation" />.
 /// </summary>
 /// <param name="opeRenomearColuna"> The operation to produce SQL for. </param>
 protected virtual void Generate(RenameColumnOperation opeRenomearColuna)
 {
     // Inicialmente não suportada
     //throw new NotSupportedException();
 }
        /// <summary>
        ///     Generates SQL for a <see cref = "RenameColumnOperation" />.
        ///     Generated SQL should be added using the Statement method.
        /// </summary>
        /// <param name = "renameColumnOperation">The operation to produce SQL for.</param>
        protected virtual void Generate(RenameColumnOperation renameColumnOperation)
        {
            Contract.Requires(renameColumnOperation != null);

            using (var writer = Writer())
            {
                writer.Write("EXECUTE sp_rename @objname = N'");
                writer.Write(renameColumnOperation.Table);
                writer.Write(".");
                writer.Write(renameColumnOperation.Name);
                writer.Write("', @newname = N'");
                writer.Write(renameColumnOperation.NewName);
                writer.Write("', @objtype = N'COLUMN'");

                Statement(writer);
            }
        }