]> 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 0a8e90f1f727ae79877bd7d4ba9252622cd6efcc..6ab25ac74810e98abc8f1f1f1a63abb7bf5c23d1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,12 @@ CHANGES
 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 f34277a9621596f794b03469409cc1dd6ec6270e..0ed4be1ba5a8e25d5235382ca1b43276cfbfc1b5 100644 (file)
@@ -780,10 +780,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 ca041ea9c2991f98ec965b402aae249146450375..f58b006dff8767ab1798440568be87d8bceb4525 100644 (file)
@@ -2490,6 +2490,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,