]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- [bug] quoting is applied to the column names
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 Jun 2012 20:49:29 +0000 (16:49 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 21 Jun 2012 20:49:29 +0000 (16:49 -0400)
inside the WITH RECURSIVE clause of a
common table expression according to the
quoting rules for the originating Column.
[ticket:2512]

CHANGES
lib/sqlalchemy/sql/compiler.py
test/sql/test_compiler.py

diff --git a/CHANGES b/CHANGES
index 5143cc218d4109a46aad25935e28a77fdc917628..d2c09e7b6dee73e822b7cd6fa7aaf4f55168f74b 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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"
index e0cdbe24c55d140362de0ae863f263d8f0e9be1c..96ca1c57d16ccfd7424c509c1a3c0d49a2b71dae 100644 (file)
@@ -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
index 4bf0eb70eac2e12e0dafe34f716c3f9583484bfc..22353f1427f33cb2d4a1b8397ac00b9441eafd79 100644 (file)
@@ -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,