diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-21 16:49:29 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-06-21 16:49:29 -0400 |
commit | d5186e92534b4d38e590cef2d56c85be845bfdf0 (patch) | |
tree | 45e774615f0f35a761a8711cddb145545f364e06 | |
parent | d5609d77841ab4e607e6b372a15396b38ddace9a (diff) | |
download | sqlalchemy-d5186e92534b4d38e590cef2d56c85be845bfdf0.tar.gz |
- [bug] quoting is applied to the column names
inside the WITH RECURSIVE clause of a
common table expression according to the
quoting rules for the originating Column.
[ticket:2512]
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | lib/sqlalchemy/sql/compiler.py | 7 | ||||
-rw-r--r-- | test/sql/test_compiler.py | 14 |
3 files changed, 25 insertions, 2 deletions
@@ -294,6 +294,12 @@ are also present in 0.8. 0.7.9 ===== - sql + - [bug] quoting is applied to the column names + inside the WITH RECURSIVE clause of a + common table expression according to the + quoting rules for the originating Column. + [ticket:2512] + - [bug] Fixed regression introduced in 0.7.6 whereby the FROM list of a SELECT statement could be incorrect in certain "clone+replace" diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index e0cdbe24c..96ca1c57d 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -790,10 +790,13 @@ class SQLCompiler(engine.Compiled): col_source = cte.original.selects[0] else: assert False - recur_cols = [c.key for c in util.unique_list(col_source.inner_columns) + recur_cols = [c for c in + util.unique_list(col_source.inner_columns) if c is not None] - text += "(%s)" % (", ".join(recur_cols)) + text += "(%s)" % (", ".join( + self.preparer.format_column(ident) + for ident in recur_cols)) text += " AS \n" + \ cte.original._compiler_dispatch( self, asfrom=True, **kwargs diff --git a/test/sql/test_compiler.py b/test/sql/test_compiler.py index 4bf0eb70e..22353f142 100644 --- a/test/sql/test_compiler.py +++ b/test/sql/test_compiler.py @@ -2486,6 +2486,20 @@ class SelectTest(fixtures.TestBase, AssertsCompiledSQL): "FROM regional_sales WHERE " "regional_sales.amount < :amount_2") + def test_cte_reserved_quote(self): + orders = table('orders', + column('order'), + ) + s = select([orders.c.order]).cte("regional_sales", recursive=True) + s = select([s.c.order]) + self.assert_compile(s, + 'WITH RECURSIVE regional_sales("order") AS ' + '(SELECT orders."order" AS "order" ' + "FROM orders)" + ' SELECT regional_sales."order" ' + "FROM regional_sales" + ) + def test_date_between(self): import datetime table = Table('dt', metadata, |