diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-05-31 20:34:03 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-01 15:37:48 -0400 |
commit | a7a19f292451e10aef489d87df27be7f58f831a8 (patch) | |
tree | c4c2c2e6c072bc6d29c2e260cd60a43a2332cc9f /test/dialect/mssql/test_compiler.py | |
parent | cbfa1363d7201848a56e7209146e81b9c51aa8af (diff) | |
download | sqlalchemy-a7a19f292451e10aef489d87df27be7f58f831a8.tar.gz |
Support multiple dotted sections in mssql schema names
Refined the logic used by the SQL Server dialect to interpret multi-part
schema names that contain many dots, to not actually lose any dots if the
name does not have bracking or quoting used, and additionally to support a
"dbname" token that has many parts including that it may have multiple,
independently-bracketed sections.
This fix addresses #5364 to some degree but probably does not
resolve it fully.
References: #5364
Fixes: #5366
Change-Id: I460cd74ce443efb35fb63b6864f00c6d81422688
Diffstat (limited to 'test/dialect/mssql/test_compiler.py')
-rw-r--r-- | test/dialect/mssql/test_compiler.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/dialect/mssql/test_compiler.py b/test/dialect/mssql/test_compiler.py index b7a06c8e3..25af3240e 100644 --- a/test/dialect/mssql/test_compiler.py +++ b/test/dialect/mssql/test_compiler.py @@ -22,6 +22,7 @@ from sqlalchemy import union from sqlalchemy import UniqueConstraint from sqlalchemy import update from sqlalchemy.dialects import mssql +from sqlalchemy.dialects.mssql import base as mssql_base from sqlalchemy.dialects.mssql import mxodbc from sqlalchemy.dialects.mssql.base import try_cast from sqlalchemy.sql import column @@ -525,6 +526,42 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): checkpositional=("bar",), ) + def test_schema_many_tokens_one(self): + metadata = MetaData() + tbl = Table( + "test", + metadata, + Column("id", Integer, primary_key=True), + schema="abc.def.efg.hij", + ) + + # for now, we don't really know what the above means, at least + # don't lose the dot + self.assert_compile( + select([tbl]), + "SELECT [abc.def.efg].hij.test.id FROM [abc.def.efg].hij.test", + ) + + dbname, owner = mssql_base._schema_elements("abc.def.efg.hij") + eq_(dbname, "abc.def.efg") + assert not isinstance(dbname, quoted_name) + eq_(owner, "hij") + + def test_schema_many_tokens_two(self): + metadata = MetaData() + tbl = Table( + "test", + metadata, + Column("id", Integer, primary_key=True), + schema="[abc].[def].[efg].[hij]", + ) + + self.assert_compile( + select([tbl]), + "SELECT [abc].[def].[efg].hij.test.id " + "FROM [abc].[def].[efg].hij.test", + ) + def test_force_schema_quoted_name_w_dot_case_insensitive(self): metadata = MetaData() tbl = Table( |