diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-03 10:28:26 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-03 10:28:26 -0400 |
| commit | 82e874b64b7a56311c10bffa4ffa151d539efe99 (patch) | |
| tree | 927abf93d61b02794db2333c09dd9f25f96cffab /test/sql | |
| parent | 48f5c2e4f7b01e075c587d3ae650eba29a1fe36e (diff) | |
| download | sqlalchemy-82e874b64b7a56311c10bffa4ffa151d539efe99.tar.gz | |
- type expressions invoke in SQL, but are only for the benefit of columns
delivered to a result set. therefore these expressions should only be rendered
for those columns that are being delivered to the result, thereby preventing
the expression from stacking onto itself within nesting scenarios.
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_type_expressions.py | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/test/sql/test_type_expressions.py b/test/sql/test_type_expressions.py index 1a331d570..320dc5d7c 100644 --- a/test/sql/test_type_expressions.py +++ b/test/sql/test_type_expressions.py @@ -2,9 +2,7 @@ from sqlalchemy import Table, Column, String, func, MetaData, select, TypeDecora from test.lib import fixtures, AssertsCompiledSQL, testing from test.lib.testing import eq_ -class SelectTest(fixtures.TestBase, AssertsCompiledSQL): - __dialect__ = 'default' - +class _ExprFixture(object): def _fixture(self): class MyString(String): def bind_expression(self, bindvalue): @@ -19,6 +17,9 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): ) return test_table +class SelectTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): + __dialect__ = 'default' + def test_select_cols(self): table = self._fixture() @@ -84,6 +85,41 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "test_table WHERE test_table.y = lower(:y_1)" ) +class DerivedTest(_ExprFixture, fixtures.TestBase, AssertsCompiledSQL): + __dialect__ = 'default' + + def test_select_from_select(self): + table = self._fixture() + self.assert_compile( + table.select().select(), + "SELECT x, lower(y) AS y FROM (SELECT test_table.x " + "AS x, test_table.y AS y FROM test_table)" + ) + + def test_select_from_alias(self): + table = self._fixture() + self.assert_compile( + table.select().alias().select(), + "SELECT anon_1.x, lower(anon_1.y) AS y FROM (SELECT " + "test_table.x AS x, test_table.y AS y " + "FROM test_table) AS anon_1" + ) + + def test_select_from_aliased_join(self): + table = self._fixture() + s1 = table.select().alias() + s2 = table.select().alias() + j = s1.join(s2, s1.c.x == s2.c.x) + s3 = j.select() + self.assert_compile(s3, + "SELECT anon_1.x, lower(anon_1.y) AS y, anon_2.x, " + "lower(anon_2.y) AS y " + "FROM (SELECT test_table.x AS x, test_table.y AS y " + "FROM test_table) AS anon_1 JOIN (SELECT " + "test_table.x AS x, test_table.y AS y " + "FROM test_table) AS anon_2 ON anon_1.x = anon_2.x" + ) + class RoundTripTestBase(object): def test_round_trip(self): testing.db.execute( |
