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:04 -0400
commit236db85f96e84fe099e63182bc4e67ceb65bd0d0 (patch)
treeeeab827ef786b6130f0b2d4d509b78d50cb96a71
parente7c179ac72abf83d32da6a79e5c94f58aa28f904 (diff)
downloadsqlalchemy-236db85f96e84fe099e63182bc4e67ceb65bd0d0.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]
-rw-r--r--doc/build/changelog/changelog_07.rst7
-rw-r--r--doc/build/changelog/changelog_08.rst8
-rw-r--r--doc/build/changelog/changelog_09.rst8
-rw-r--r--lib/sqlalchemy/sql/compiler.py2
-rw-r--r--test/sql/test_cte.py16
5 files changed, 40 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 952c45662..9d7b4b975 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/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst
index 3e755125b..cc9954120 100644
--- a/doc/build/changelog/changelog_09.rst
+++ b/doc/build/changelog/changelog_09.rst
@@ -7,6 +7,14 @@
:version: 0.9.0
.. 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.8.3, 0.7.11.
+
+ .. change::
:tags: bug, mysql
Improved support for the cymysql driver, supporting version 0.6.5,
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index a6e6987c5..dc3d55039 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -1049,7 +1049,7 @@ class SQLCompiler(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'),