diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-05-27 19:22:59 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-05-27 19:22:59 -0400 |
| commit | a9ed16f80d5e6d96d800004953b555b9cf1a592e (patch) | |
| tree | 253f56891eea6e9edcd333d03daac6cbb5dfb600 /test/sql/test_compiler.py | |
| parent | e2b8c893ca98bb0141405a7d7d40c4024d5bdf41 (diff) | |
| download | sqlalchemy-a9ed16f80d5e6d96d800004953b555b9cf1a592e.tar.gz | |
attempt number one, doesn't detect though if the label in the order by is not directly present there.
Diffstat (limited to 'test/sql/test_compiler.py')
| -rw-r--r-- | test/sql/test_compiler.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 9cd893c1a..887676f94 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -746,6 +746,69 @@ 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. + + 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. + + """ + 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 " + "ORDER BY foo, bar DESC", + dialect=dialect + ) + + # the function embedded label renders as the function + self.assert_compile( + select([lab1, lab2]).order_by(func.hoho(lab1), desc(lab2)), + "SELECT mytable.myid + :myid_1 AS foo, " + "somefunc(mytable.name) AS bar FROM mytable " + "ORDER BY hoho(mytable.myid + :myid_1), bar DESC", + dialect=dialect + ) + + # binary expressions render as the expression without labels + self.assert_compile(select([lab1, lab2]).order_by(lab1 + "test"), + "SELECT mytable.myid + :myid_1 AS foo, " + "somefunc(mytable.name) AS bar FROM mytable " + "ORDER BY mytable.myid + :myid_1 + :param_1", + dialect=dialect + ) + + # labels within functions in the columns clause render + # with the expression + self.assert_compile( + select([lab1, func.foo(lab1)]), + "SELECT mytable.myid + :myid_1 AS foo, " + "foo(mytable.myid + :myid_1) AS foo_1 FROM mytable", + dialect=dialect + ) + + dialect = default.DefaultDialect() + dialect.supports_simple_order_by_label = False + 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 " + "ORDER BY mytable.myid + :myid_1, somefunc(mytable.name) DESC", + dialect=dialect + ) + self.assert_compile( + select([lab1, lab2]).order_by(func.hoho(lab1), desc(lab2)), + "SELECT mytable.myid + :myid_1 AS foo, " + "somefunc(mytable.name) AS bar FROM mytable " + "ORDER BY hoho(mytable.myid + :myid_1), " + "somefunc(mytable.name) DESC", + dialect=dialect + ) + def test_conjunctions(self): a, b, c = 'a', 'b', 'c' x = and_(a, b, c) |
