diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-05-27 21:05:16 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-05-27 21:05:16 -0400 |
commit | 0adcfea0d30376461c75cced87481f04a42481c0 (patch) | |
tree | 9072ec2d98598591629dd9848cfa91ca62764f47 /test/sql/test_compiler.py | |
parent | a9ed16f80d5e6d96d800004953b555b9cf1a592e (diff) | |
download | sqlalchemy-0adcfea0d30376461c75cced87481f04a42481c0.tar.gz |
still not locating more nested expressions, may need to match on name
Diffstat (limited to 'test/sql/test_compiler.py')
-rw-r--r-- | test/sql/test_compiler.py | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 887676f94..d5f52bdf3 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -746,19 +746,24 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): 'foo || :param_1') - def test_labels_in_expressions(self): - """test that label() constructs in ORDER BY render as the labelname. + def test_foo(self): + lx = (table1.c.myid + table1.c.myid).label('lx') + ly = (func.lower(table1.c.name) + table1.c.description).label('ly') + dialect = default.DefaultDialect() - Postgres' behavior was used as the guide for this, - so that only a simple label expression - and not a more complex expression involving the label - name would be rendered using the label name. + self.assert_compile( + select([lx, ly]).order_by(lx, ly.desc()), + "SELECT mytable.myid + mytable.myid AS lx, " + "lower(mytable.name) || mytable.description AS ly " + "FROM mytable ORDER BY lx, ly DESC", + dialect=dialect + ) - """ - lab1 = (table1.c.myid + "12").label('foo') + def test_labels_in_expressions(self): + lab1 = (table1.c.myid + 12).label('foo') lab2 = func.somefunc(table1.c.name).label('bar') - dialect = default.DefaultDialect() + self.assert_compile(select([lab1, lab2]).order_by(lab1, desc(lab2)), "SELECT mytable.myid + :myid_1 AS foo, " "somefunc(mytable.name) AS bar FROM mytable " @@ -786,9 +791,22 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): # labels within functions in the columns clause render # with the expression self.assert_compile( - select([lab1, func.foo(lab1)]), + select([lab1, func.foo(lab1)]).order_by(lab1, func.foo(lab1)), "SELECT mytable.myid + :myid_1 AS foo, " - "foo(mytable.myid + :myid_1) AS foo_1 FROM mytable", + "foo(mytable.myid + :myid_1) AS foo_1 FROM mytable " + "ORDER BY foo, foo(mytable.myid + :myid_1)", + dialect=dialect + ) + + + lx = (table1.c.myid + table1.c.myid).label('lx') + ly = (func.lower(table1.c.name) + table1.c.description).label('ly') + + self.assert_compile( + select([lx, ly]).order_by(lx, ly.desc()), + "SELECT mytable.myid + mytable.myid AS lx, " + "lower(mytable.name) || mytable.description AS ly " + "FROM mytable ORDER BY lx, ly DESC", dialect=dialect ) |