On Sunday, February 4, 2018 at 5:32:47 PM UTC-8, Tom Wardrop wrote:
>
> Not sure if this a bug, but check the following:
>
> # Adds column "TEST" to "RESOURCE" table.
> add_column :resource, :test, :bit
>
> # Renames "TEST" to "another_test" in lower case
> rename_column :resource, :test, :another_test
>
> This is using the TinyTDS adapter. Adding columns automatically converts 
> column names to uppercase, where as renaming does not.
>
> Thoughts?
>

Microsoft SQL Server doesn't actually have syntax support for renaming 
columns, you have to call the sp_rename stored procedure, and you pass that 
procedure a string, not an identifier.  I'm not sure what the quoting rules 
are regarding that string, I'll have to experiment tomorrow and see if 
there is a bug.  Considering that MSSQL can pass the related specs, it 
seems unlikely there is a bug, unless you have noticed an actual problem 
and not just worried that the generated SQL looks odd.

You could try the following, but I have no idea if it works as I haven't 
tested it:

diff --git a/lib/sequel/adapters/shared/mssql.rb 
b/lib/sequel/adapters/shared/mssql.rb
index 68dd4d1fd..8365701fa 100644
--- a/lib/sequel/adapters/shared/mssql.rb
+++ b/lib/sequel/adapters/shared/mssql.rb
@@ -260,7 +260,7 @@ module Sequel
           add_drop_default_constraint_sql(sqls, table, op[:name])
           sqls << super
         when :rename_column
-          "sp_rename 
#{literal("#{quote_schema_table(table)}.#{quote_identifier(op[:name])}")}, 
#{literal(op[:new_name].to_s)}, 'COLUMN'"
+          "sp_rename 
#{literal("#{quote_schema_table(table)}.#{quote_identifier(op[:name])}")}, 
#{literal(metadata_dataset.with_quote_identifiers(false).quote_identifier(op[:new_name]))},
 
'COLUMN'"
         when :set_column_type
           sqls = []
           if sch = schema(table)


Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To post to this group, send email to sequel-talk@googlegroups.com.
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to