]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
Fixed bug whereby double quoting would be applied
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Apr 2013 19:43:33 +0000 (15:43 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 4 Apr 2013 19:43:33 +0000 (15:43 -0400)
to target column name during an ``sp_rename``
operation.
#109

alembic/ddl/mssql.py
docs/build/changelog.rst
tests/test_mssql.py

index 8011495e6d5616f3c00c2837569e49dd72053e91..0f2a7592631d8d36b6a3eac9a2ed13bf18d86c8e 100644 (file)
@@ -156,7 +156,7 @@ def visit_column_default(element, compiler, **kw):
 
 @compiles(ColumnName, 'mssql')
 def visit_rename_column(element, compiler, **kw):
-    return "EXEC sp_rename '%s.%s', '%s', 'COLUMN'" % (
+    return "EXEC sp_rename '%s.%s', %s, 'COLUMN'" % (
         format_table_name(compiler, element.table_name, element.schema),
         format_column_name(compiler, element.column_name),
         format_column_name(compiler, element.newname)
index f87deed30cbd160ef6e8b37509244cff63582779..aee64a7593839a1ac5c1b0021557c54276a0b064 100644 (file)
@@ -6,6 +6,14 @@ Changelog
 .. changelog::
     :version: 0.5.0
 
+    .. change::
+        :tags: bug, mssql
+        :tickets: 109
+
+      Fixed bug whereby double quoting would be applied
+      to target column name during an ``sp_rename``
+      operation.
+
     .. change::
         :tags: bug
         :tickets: 112
index 0948581ab26f6117194a2985aa2bf5fa9e27c5b6..66cdb9a505af47de340f4ad33075a771c0aa2a40 100644 (file)
@@ -53,7 +53,14 @@ class OpTest(TestCase):
         context = op_fixture('mssql')
         op.alter_column("t", "c", new_column_name="x")
         context.assert_(
-            "EXEC sp_rename 't.c', 'x', 'COLUMN'"
+            "EXEC sp_rename 't.c', x, 'COLUMN'"
+        )
+
+    def test_alter_column_rename_quoted_mssql(self):
+        context = op_fixture('mssql')
+        op.alter_column("t", "c", new_column_name="SomeFancyName")
+        context.assert_(
+            "EXEC sp_rename 't.c', [SomeFancyName], 'COLUMN'"
         )
 
     def test_alter_column_new_type(self):
@@ -157,7 +164,7 @@ class OpTest(TestCase):
         context.assert_(
             'ALTER TABLE t ALTER COLUMN c INTEGER NULL',
             "ALTER TABLE t ADD DEFAULT '5' FOR c",
-            "EXEC sp_rename 't.c', 'c2', 'COLUMN'"
+            "EXEC sp_rename 't.c', c2, 'COLUMN'"
         )
 
     # TODO: when we add schema support