Don't use schema with second argument, SQL Server sp_rename

Repaired :meth:`.Operations.rename_table` for SQL Server when the
target table is in a remote schema, the schema name is omitted from
the "new name" argument.

Also added some extra tests for sp_rename w/ quoting / case sensitive
names.

Change-Id: I411b32d0c5bba5a466c0b5d6a412c1b7541fdc95
Fixes: #429
This commit is contained in:
Mike Bayer 2017-05-18 10:36:13 -04:00
parent fbbb669b8c
commit c7da7f2d08
3 changed files with 36 additions and 8 deletions

View File

@ -229,5 +229,5 @@ def visit_column_type(element, compiler, **kw):
def visit_rename_table(element, compiler, **kw):
return "EXEC sp_rename '%s', %s" % (
format_table_name(compiler, element.table_name, element.schema),
format_table_name(compiler, element.new_table_name, element.schema)
format_table_name(compiler, element.new_table_name, None)
)

View File

@ -7,6 +7,14 @@ Changelog
:version: 0.9.2
:released:
.. change:: 429
:tags: bug, mssql
:tickets: 429
Repaired :meth:`.Operations.rename_table` for SQL Server when the
target table is in a remote schema, the schema name is omitted from
the "new name" argument.
.. change:: 425
:tags: feature, commands
:tickets: 425

View File

@ -252,10 +252,30 @@ class OpTest(TestBase):
op.rename_table('t1', 't2')
context.assert_contains("EXEC sp_rename 't1', t2")
# TODO: when we add schema support
# def test_alter_column_rename_mssql_schema(self):
# context = op_fixture('mssql')
# op.alter_column("t", "c", name="x", schema="y")
# context.assert_(
# "EXEC sp_rename 'y.t.c', 'x', 'COLUMN'"
# )
def test_rename_table_schema(self):
context = op_fixture('mssql')
op.rename_table('t1', 't2', schema="foobar")
context.assert_contains("EXEC sp_rename 'foobar.t1', t2")
def test_rename_table_casesens(self):
context = op_fixture('mssql')
op.rename_table('TeeOne', 'TeeTwo')
# yup, ran this in SQL Server 2014, the two levels of quoting
# seems to be understood. Can't do the two levels on the
# target name though !
context.assert_contains("EXEC sp_rename '[TeeOne]', [TeeTwo]")
def test_rename_table_schema_casesens(self):
context = op_fixture('mssql')
op.rename_table('TeeOne', 'TeeTwo', schema="FooBar")
# yup, ran this in SQL Server 2014, the two levels of quoting
# seems to be understood. Can't do the two levels on the
# target name though !
context.assert_contains("EXEC sp_rename '[FooBar].[TeeOne]', [TeeTwo]")
def test_alter_column_rename_mssql_schema(self):
context = op_fixture('mssql')
op.alter_column("t", "c", name="x", schema="y")
context.assert_(
"EXEC sp_rename 'y.t.c', x, 'COLUMN'"
)