diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-28 14:03:47 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-02-28 14:52:28 -0500 |
commit | b4e880534e1e02815e95f105a4363bef8ee86130 (patch) | |
tree | 751f036c9e757887c7b092f36839dc5963ece1e3 /test/sql/test_compiler.py | |
parent | ff2090336f7c160e58774e7504bd4f7aca919dff (diff) | |
download | sqlalchemy-b4e880534e1e02815e95f105a4363bef8ee86130.tar.gz |
Only use schema_translate_map on SchemaItem subclasses
Fixed bug in new "schema translate" feature where the translated schema
name would be invoked in terms of an alias name when rendered along
with a column expression; occurred only when the source translate
name was "None". The "schema translate" feature now only takes
effect for :class:`.SchemaItem` and :class:`.SchemaType` subclasses,
that is, objects that correspond to a DDL-creatable structure in
a database.
Change-Id: Ie8cb35aeaba2c67efec8c8c57c219e4dd346e44a
Fixes: #3924
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r-- | test/sql/test_compiler.py | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index e7504a748..e65db2a36 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -3374,6 +3374,12 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): ) def test_schema_translate_select(self): + m = MetaData() + table1 = Table( + 'mytable', m, Column('myid', Integer), + Column('name', String), + Column('description', String) + ) schema_translate_map = {"remote_owner": "foob", None: 'bar'} self.assert_compile( @@ -3402,13 +3408,51 @@ class SchemaTest(fixtures.TestBase, AssertsCompiledSQL): "SELECT mytable.myid, mytable.name, mytable.description, " "foob.remotetable.rem_id, foob.remotetable.datatype_id, " "foob.remotetable.value FROM mytable JOIN foob.remotetable " - "ON foob.remotetable.rem_id = mytable.myid", + "ON mytable.myid = foob.remotetable.rem_id", + schema_translate_map=schema_translate_map + ) + + def test_schema_translate_aliases(self): + schema_translate_map = {None: 'bar'} + + m = MetaData() + table1 = Table( + 'mytable', m, Column('myid', Integer), + Column('name', String), + Column('description', String) + ) + table2 = Table( + 'myothertable', m, Column('otherid', Integer), + Column('othername', String), + ) + + alias = table1.alias() + + stmt = select([ + table2, alias + ]).select_from(table2.join(alias, table2.c.otherid == alias.c.myid)).\ + where(alias.c.name == 'foo') + + self.assert_compile( + stmt, + "SELECT bar.myothertable.otherid, bar.myothertable.othername, " + "mytable_1.myid, mytable_1.name, mytable_1.description " + "FROM bar.myothertable JOIN bar.mytable AS mytable_1 " + "ON bar.myothertable.otherid = mytable_1.myid " + "WHERE mytable_1.name = :name_1", schema_translate_map=schema_translate_map ) def test_schema_translate_crud(self): schema_translate_map = {"remote_owner": "foob", None: 'bar'} + m = MetaData() + table1 = Table( + 'mytable', m, + Column('myid', Integer), Column('name', String), + Column('description', String) + ) + self.assert_compile( table1.insert().values(description='foo'), "INSERT INTO bar.mytable (description) VALUES (:description)", |