summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2013-08-18 14:46:04 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2013-08-18 14:46:34 -0400
commit4f0bda7c455a642b505d6133002c4a5fb1e88876 (patch)
tree4da78018f48a59dc150908ab8c2183c0b16f64c6
parent5cbf8be95d1ad00285dce9a0418337ea66194051 (diff)
downloadsqlalchemy-4f0bda7c455a642b505d6133002c4a5fb1e88876.tar.gz
Fixed regression dating back to 0.7.9 whereby the name of a CTE might
not be properly quoted if it was referred to in multiple FROM clauses. Also in 0.8.3, 0.7.11. [ticket:2801] Conflicts: doc/build/changelog/changelog_09.rst
-rw-r--r--doc/build/changelog/changelog_07.rst7
-rw-r--r--doc/build/changelog/changelog_08.rst8
-rw-r--r--lib/sqlalchemy/sql/compiler.py2
-rw-r--r--test/sql/test_cte.py16
4 files changed, 32 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_07.rst b/doc/build/changelog/changelog_07.rst
index 3504a5134..c6da742b8 100644
--- a/doc/build/changelog/changelog_07.rst
+++ b/doc/build/changelog/changelog_07.rst
@@ -7,6 +7,13 @@
:version: 0.7.11
.. change::
+ :tags: bug, sql
+ :tickets: 2801
+
+ Fixed regression dating back to 0.7.9 whereby the name of a CTE might
+ not be properly quoted if it was referred to in multiple FROM clauses.
+
+ .. change::
:tags: mysql, bug
:tickets: 2791
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst
index 8e4fe4b4a..bbd2741c8 100644
--- a/doc/build/changelog/changelog_08.rst
+++ b/doc/build/changelog/changelog_08.rst
@@ -7,6 +7,14 @@
:version: 0.8.3
.. change::
+ :tags: bug, sql
+ :tickets: 2801
+
+ Fixed regression dating back to 0.7.9 whereby the name of a CTE might
+ not be properly quoted if it was referred to in multiple FROM clauses.
+ Also in 0.7.11.
+
+ .. change::
:tags: bug, examples
Added "autoincrement=False" to the history table created in the
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 5f286a331..01959ee18 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -913,7 +913,7 @@ class SQLCompiler(engine.Compiled):
# we've generated a same-named CTE that we are enclosed in,
# or this is the same CTE. just return the name.
if cte in existing_cte._restates or cte is existing_cte:
- return cte_name
+ return self.preparer.format_alias(cte, cte_name)
elif existing_cte in cte._restates:
# we've generated a same-named CTE that is
# enclosed in us - we take precedence, so
diff --git a/test/sql/test_cte.py b/test/sql/test_cte.py
index 5368b9891..0f6831375 100644
--- a/test/sql/test_cte.py
+++ b/test/sql/test_cte.py
@@ -312,6 +312,22 @@ class CTETest(fixtures.TestBase, AssertsCompiledSQL):
"FROM regional_sales"
)
+ def test_multi_subq_quote(self):
+ cte = select([literal(1).label("id")]).cte(name='CTE')
+
+ s1 = select([cte.c.id]).alias()
+ s2 = select([cte.c.id]).alias()
+
+ s = select([s1, s2])
+ self.assert_compile(
+ s,
+ 'WITH "CTE" AS (SELECT :param_1 AS id) '
+ 'SELECT anon_1.id, anon_2.id FROM '
+ '(SELECT "CTE".id AS id FROM "CTE") AS anon_1, '
+ '(SELECT "CTE".id AS id FROM "CTE") AS anon_2'
+ )
+
+
def test_positional_binds(self):
orders = table('orders',
column('order'),